GithubHelp home page GithubHelp logo

SlidableController about flutter_slidable HOT 6 CLOSED

letsar avatar letsar commented on June 24, 2024
SlidableController

from flutter_slidable.

Comments (6)

MrMagloire avatar MrMagloire commented on June 24, 2024 1

aweasome, thank you, all is good now

from flutter_slidable.

letsar avatar letsar commented on June 24, 2024

Hi @MrMagloire ,
Can you post the minimal code sample to reproduce this issue, please?

from flutter_slidable.

MrMagloire avatar MrMagloire commented on June 24, 2024

@letsar

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:gbame_app/routes/my_navigator.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:gbame_app/services/type.dart';
import 'package:gbame_app/tools/loading.dart';

class Index extends StatefulWidget {
static const String routeName = "/type_index";
@OverRide
_IndexState createState() => _IndexState();
}

class _IndexState extends State {
final CollectionReference typeCollection = Firestore.instance.collection('Types');
final GlobalKey _scaffoldkey = new GlobalKey();
TypeStorage typeStorage = new TypeStorage();
final SlidableController slidableController = new SlidableController();

@override
Widget build(BuildContext context) {
	return new Scaffold(
		key: _scaffoldkey,
		appBar: new AppBar(
			title: new Text("Types de Gbamé"),
		),
		body: new StreamBuilder<QuerySnapshot>(
			stream: typeCollection.snapshots(),
			builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
				if (!snapshot.hasData)
					return Loading();
				final int typeCount = snapshot.data.documents.length;
				return new ListView.builder(
					itemCount: typeCount,
					itemBuilder: (_, int index) {
						final DocumentSnapshot document = snapshot.data.documents[index];
						return listType(document);
					},
				);
			},
		),
		floatingActionButton: FloatingActionButton(
			child: const Icon(Icons.add),
			elevation: 4.0,
			onPressed: _goToAdd,
		),
	);
}

void _goToAdd() {
	MyNavigator.goToTypeAdd(context);
}

_slideAction(String action, DocumentSnapshot document) {
	switch (action) {
		case 'delete':
			typeStorage.delete(document['id'])
			.then((_){
				_showSucces(action);
			})
			.catchError((_) {
				_showError(action);
			});
			break;
		default:
	}
}

Future _showSucces(String action) async {
	Timer(Duration(seconds: 2), () {
		final _snackbar = new SnackBar(
			content: new Text(
				"$action effectué avec succes"
			),
			duration: new Duration(seconds: 5),
			backgroundColor: Colors.teal.shade900,
		);
		_scaffoldkey.currentState.showSnackBar(_snackbar);
	});
}

Future _showError(String action) async {
	Timer(Duration(seconds: 2), () {
		final _snackbar = new SnackBar(
			content: new Text(
				"$action Erreur !!"
			),
			duration: new Duration(seconds: 5),
			backgroundColor: Colors.red,
		);
		_scaffoldkey.currentState.showSnackBar(_snackbar);
	});
}

Widget listType(DocumentSnapshot document) => Slidable(
    // controller: slidableController,
	delegate: new SlidableStrechDelegate(),
	actionExtentRatio: 0.25,
	secondaryActions: <Widget>[
		new IconSlideAction(
			caption: 'Modifier',
			color: Colors.lightBlueAccent,
			icon: Icons.mode_edit,
			onTap: () {
				_slideAction('edit',document);
			},
		),
		new IconSlideAction(
			caption: 'Supprimer',
			color: Colors.red,
			icon: Icons.delete_forever,
			onTap: () {
				_slideAction('delete',document);
			},
		)
	],
	child: new ListTile(
		title: Container(
			decoration: BoxDecoration(
				border: new Border(
					left: new BorderSide(width: 4.0, color: Colors.lightGreen)
				),
			),
			padding: EdgeInsets.all(5.0),
			child: Row(
				children: <Widget>[
					Icon(
					FontAwesomeIcons.busAlt,
					color: Colors.teal.shade900,
					),
					SizedBox(
					width: 10.0,
					),
					new Text(document['name'] ?? '<No type retrieved>')
				],
			),
		),
	),
);

}

from flutter_slidable.

letsar avatar letsar commented on June 24, 2024

Should be fixed in version 0.4.2

from flutter_slidable.

MrMagloire avatar MrMagloire commented on June 24, 2024

Waiting for that, thank you for all

from flutter_slidable.

letsar avatar letsar commented on June 24, 2024

It is published :-). Can you test it?

from flutter_slidable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.