Advertisement
Guest User

Untitled

a guest
Mar 13th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.11 KB | None | 0 0
  1. class QRView extends StatefulWidget {
  2.   const QRView({this.num, this.user, this.data});
  3.   final int num;
  4.   final DocumentSnapshot data;
  5.   final FirebaseUser user;
  6.   @override
  7.   _QRViewState createState() => _QRViewState();
  8. }
  9.  
  10. class _QRViewState extends State<QRView> {
  11.   @override
  12.   void initState() {
  13.     // TODO: implement initState
  14.     setState(() {});
  15.     super.initState();
  16.   }
  17.  
  18.   @override
  19.   Widget build(BuildContext context) {
  20.     return Hero(
  21.         tag: "card${widget.num}",
  22.         child: SafeArea(
  23.             child: Scaffold(
  24.           resizeToAvoidBottomPadding: false,
  25.           backgroundColor: Colors.teal,
  26.           floatingActionButton: FloatingActionButton.extended(
  27.             backgroundColor: Colors.white.withOpacity(0.8),
  28.             foregroundColor: Colors.teal,
  29.             onPressed: () {
  30.               return showDialog(
  31.                   context: context,
  32.                   builder: (BuildContext context) {
  33.                     return CrearView(widget.data);
  34.                   });
  35.             },
  36.             icon: Icon(Icons.add),
  37.             label: Text("Nuevo QR"),
  38.           ),
  39.           appBar: AppBar(
  40.               backgroundColor: Colors.white.withOpacity(0.8),
  41.               centerTitle: true,
  42.               title: Text(
  43.                 "Entrada QR",
  44.                 style: TextStyle(color: Colors.teal, fontFamily: "Mono"),
  45.               )),
  46.           body: SafeArea(
  47.             child: StreamBuilder(
  48.     stream: Firestore.instance
  49.         .collection("CondosDB")
  50.         .document(widget.data.documentID)
  51.         .collection("QR")
  52.         .orderBy("fecha", descending: true)
  53.         .snapshots(),
  54.     builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
  55.       if (snapshot.hasError) return new Text('${snapshot.error}');
  56.  
  57.       switch (snapshot.connectionState) {
  58.         case ConnectionState.waiting:
  59.           return Text("retorno waiting");
  60.  
  61.         default:
  62.           var qrs = snapshot.data.documents;
  63.  
  64.           if (qrs.isEmpty) {
  65.             return Container(
  66.               child: Center(
  67.                 child: Text(
  68.                   "Para añadir tu primer código QR, presiona el botón +",
  69.                   style: TextStyle(
  70.                     color: Colors.white.withOpacity(0.8),
  71.                     fontSize: 30.0,
  72.                   ),
  73.                   textAlign: TextAlign.center,
  74.                 ),
  75.               ),
  76.             );
  77.           } else {
  78.             return ListView.builder(
  79.                 reverse: false,
  80.                 itemCount: qrs.length,
  81.                 shrinkWrap: true,
  82.                 scrollDirection: Axis.vertical,
  83.                 itemBuilder: (BuildContext context, int index) {
  84.                   var qr = qrs[index];
  85.                   return Container(
  86.                     color: Colors.white.withOpacity(0.3),
  87.                     child: ListTile(
  88.                       title: Text(qr["titulo"]),
  89.                       subtitle: Text(qr.documentID),
  90.                     ),
  91.                   );
  92.                 });
  93.           }
  94.       }
  95.     },
  96.   ),
  97.           ),
  98.         )));
  99.   }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement