Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.89 KB | None | 0 0
  1. class AfterHero extends StatefulWidget {
  2.   const AfterHero(this.data, this.user, this.post);
  3.   final DocumentSnapshot data;
  4.   final FirebaseUser user;
  5.   final DocumentSnapshot post;
  6.   @override
  7.   _AfterHeroState createState() => _AfterHeroState();
  8. }
  9.  
  10. class _AfterHeroState extends State<AfterHero> {
  11.   @override
  12.   Widget build(BuildContext context) {
  13.   return Hero(
  14.       tag: widget.post["kind"],
  15.       child: Scaffold(
  16.         backgroundColor: Colors.teal,
  17.         appBar: AppBar(
  18.           title: Text(
  19.             widget.post["kind"],
  20.             style: TextStyle(fontFamily: 'Mono', fontSize: 20.0),
  21.           ),
  22.           centerTitle: true,
  23.           titleSpacing: 0.0,
  24.           backgroundColor: Colors.teal,
  25.           textTheme: TextTheme(title: TextStyle(color: Colors.white)),
  26.         ),
  27.         body: StreamBuilder(
  28.             stream: Firestore.instance
  29.                 .collection('TranquiDB')
  30.                 .where("condo", isEqualTo: widget.data["condo"])
  31.                 .snapshots(),
  32.             builder:
  33.                 (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
  34.               if (snapshot.hasError) return new Text('${snapshot.error}');
  35.               switch (snapshot.connectionState) {
  36.                 case ConnectionState.waiting:
  37.                   return new Center(
  38.                     child: CircularProgressIndicator(),
  39.                   );
  40.                 default:
  41.                   final accounts = snapshot.data.documents;
  42.                   if (accounts.isEmpty) {
  43.                     return Container(
  44.                       child: Center(
  45.                         child: Text(
  46.                           "No hay Usuarios a quien notificar sobre ${widget.post["kind"]}",
  47.                           style: TextStyle(
  48.                             color: Colors.white.withOpacity(0.8),
  49.                             fontSize: 30.0,
  50.                           ),
  51.                           textAlign: TextAlign.center,
  52.                         ),
  53.                       ),
  54.                     );
  55.                   } else {
  56.                     List<DocumentSnapshot> wantedAccounts=[];
  57.                     accounts.forEach((acc){
  58.                       print(acc["nombreParaMostrar"]);
  59.                       if (widget.post["destinatarios"].contains(acc["perfil"])) {
  60.                         wantedAccounts.add(acc);
  61.                       }
  62.                     });
  63.                     print(wantedAccounts);
  64.                     return new ListView.builder(
  65.                         reverse: false,
  66.                         itemCount: wantedAccounts.length,
  67.                         scrollDirection: Axis.vertical,
  68.                         itemBuilder: (BuildContext context, int index) {
  69.                           var acc = wantedAccounts[index];
  70.                           return Hero(
  71.                             tag: acc["nombreParaMostrar"],
  72.                             child: Card(
  73.                               elevation: 10.0,
  74.                               color: Colors.white,
  75.                               child: ListTile(
  76.                                 leading: Icon(Icons.arrow_forward_ios),
  77.                                 title: Text(acc["nombreParaMostrar"]),
  78.                                 subtitle: Text('Presionar para Notificar.'),
  79.                                 onTap: () {
  80.                                   Navigator.push(
  81.                                       context,
  82.                                       new MaterialPageRoute(
  83.                                           builder: (context) => AfterHeroUser(
  84.                                               widget.data, widget.user, widget.post, acc)));
  85.                                 },
  86.                               ),
  87.                             ),
  88.                           );
  89.                         });
  90.                   }
  91.               }
  92.             }),
  93.         )
  94.     );
  95.   }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement