Instantly share code, notes, and snippets.

@ijoschek /.\lib\scr\home.dart Secret
Last active Dec 5, 2018

Embed
What would you like to do?
flutter_firestore_tut
//...
class _Home extends State<StatefulWidget> {
//...
void switchListener(isOn) async {
bool switcher;
switch (isOn) {
case true:
switcher = true;
_listener = Firestore.instance
.collection('docs')
.snapshots()
.listen((data) => listenerUpdate(data));
break;
case false:
switcher = false;
await _listener.cancel();
break;
}
setState(() {
_switchOnOff = switcher;
});
}
void listenerUpdate(data) {
var number = data.documents.length;
setState(() {
_totalDocs = number;
});
}
//...
@override
Widget build(BuildContext context) {
return Scaffold(
//...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment