Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SlidableController #22

Closed
MrMagloire opened this issue Aug 10, 2018 · 6 comments
Closed

SlidableController #22

MrMagloire opened this issue Aug 10, 2018 · 6 comments
Assignees

Comments

@MrMagloire
Copy link

Since i have added controller to my slidable, i encounter other error that i don't know where they come, i see error when i pop page [ statefulWidget ], but when i comment line of controller, all pass good.

captureslidable
captureslidable2

@letsar
Copy link
Owner

letsar commented Aug 19, 2018

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

@letsar letsar self-assigned this Aug 19, 2018
@MrMagloire
Copy link
Author

@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>')
				],
			),
		),
	),
);

}

@letsar
Copy link
Owner

letsar commented Aug 22, 2018

Should be fixed in version 0.4.2

@MrMagloire
Copy link
Author

Waiting for that, thank you for all

@letsar
Copy link
Owner

letsar commented Aug 23, 2018

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

@MrMagloire
Copy link
Author

aweasome, thank you, all is good now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants