Cleanup and widget refactor

This commit is contained in:
Ricardo Markiewicz
2020-07-16 16:26:51 -03:00
parent 7f6dfa4fa3
commit a416359a43
8 changed files with 255 additions and 138 deletions
+31
View File
@@ -0,0 +1,31 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
class StreamWidget extends StatelessWidget {
final Stream<QuerySnapshot> stream;
final Widget Function(BuildContext) empty;
final Widget Function(BuildContext) loading;
final Widget Function(BuildContext, QuerySnapshot) done;
const StreamWidget(
{Key key, this.stream, this.empty, this.loading, this.done})
: super(key: key);
@override
Widget build(BuildContext _) {
return StreamBuilder<QuerySnapshot>(
stream: stream,
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> data) {
if (data.connectionState == ConnectionState.active) {
if (data.data.documents.length > 0) {
return done(context, data.data);
} else {
return empty(context);
}
}
return loading(context);
},
);
}
}