Advertisement
Guest User

Untitled

a guest
Jan 10th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.86 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:rezervisanje/globals.dart' as globals;
  3. import 'dart:async';
  4. import 'package:cloud_firestore/cloud_firestore.dart';
  5.  
  6. class ReserveTable extends StatefulWidget {
  7.   @override
  8.   _ReserveTableState createState() => _ReserveTableState();
  9. }
  10.  
  11. class _ReserveTableState extends State<ReserveTable> {
  12.   var sum;
  13.   var step = 0;
  14.   var hours = 0;
  15.   var minutes = 0;
  16.   DateTime times;
  17.   final List<LoadList> terminlist = new List();
  18.   final List<LoadList> items = new List();
  19.   final formKey = GlobalKey<FormState>();
  20.   Future<int> firebaseQuery;
  21.   @override
  22.   void initState() {
  23.     super.initState();
  24.     firebaseQuery = Firestore.instance
  25.         .collection('salons')
  26.         .document(globals.salonkey)
  27.         .get()
  28.         .then((document) {
  29.       setState(() {
  30.         globals.shiftstart = document.data['firstshiftstart'];
  31.         globals.shiftend = document.data['firstshiftend'];
  32.       });
  33.     });
  34.   }
  35.  
  36.   @override
  37.   Widget build(BuildContext context) {
  38.     if (globals.day == null) {
  39.       globals.day = DateTime(
  40.           DateTime.now().year, DateTime.now().month, DateTime.now().day);
  41.     }
  42.     times = globals.day.add(new Duration(days: -1));
  43.     new FutureBuilder(
  44.       future: firebaseQuery,
  45.       builder: (context, snapshot) {
  46.         if (snapshot.hasError) {
  47.           print("snapErr");//not getting printed
  48.           return new Text("${snapshot.error}");
  49.         } else
  50.           items.clear();
  51.         print("SHIFTEND " + globals.shiftend.toString());//not getting printed
  52.       },
  53.     );
  54.     new StreamBuilder<QuerySnapshot>(
  55.         stream: Firestore.instance
  56.             .collection('termins')
  57.             .where('time', isLessThanOrEqualTo: globals.day)
  58.             .where('time', isGreaterThanOrEqualTo: times)
  59.             .where('employeeID', isEqualTo: globals.employeeID)
  60.             .snapshots(),
  61.         builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
  62.           print("2");//not getting printed
  63.           if (!snapshot.hasData)
  64.             return const Text('Connecting...');
  65.           else {
  66.             print('3');//not getting printed
  67.             sum = snapshot.data.documents.length;
  68.             for (int i = 0; i < sum; i++) {
  69.               DocumentSnapshot items = snapshot.data.documents[i];
  70.               DateTime date = items['time'];
  71.               terminlist.add(new LoadList(date.hour, date.minute));
  72.             }
  73.           }
  74.         });
  75.  
  76.     int div =
  77.         ((globals.shiftend - globals.shiftstart) * 60 / globals.requiredtime)
  78.             .round();
  79.     hours = globals.shiftstart;
  80.     for (var i = 0; i < div; i++) {
  81.       if (minutes == 60) {
  82.         minutes = 0;
  83.         hours = hours + 1;
  84.       }
  85.       items.add(new LoadList(hours, minutes));
  86.       minutes += globals.requiredtime;
  87.     }
  88.  
  89.     return new Scaffold(
  90.         appBar: new AppBar(
  91.           title:
  92.               new Text(globals.employee == "" ? "Reserve" : globals.employee),
  93.           backgroundColor: Colors.deepOrange,
  94.         ),
  95.         drawer: new Drawer(
  96.             child: new ListView(children: <Widget>[
  97.           new ListTile(
  98.               title: new Text("Close"),
  99.               trailing: new Icon(Icons.arrow_upward),
  100.               onTap: () {
  101.                 Navigator.of(context).pop();
  102.               })
  103.         ])),
  104.         body: Card(
  105.             child: Padding(
  106.           padding: EdgeInsets.all(8.0),
  107.           child: Form(
  108.               key: formKey,
  109.               child: new ListView.builder(
  110.                   scrollDirection: Axis.vertical,
  111.                   itemCount: items.length,
  112.                   itemBuilder: (context, index) {
  113.                     print(sum);//only this is getting printed,its null
  114.                   })),
  115.         )));
  116.   }
  117. }
  118.  
  119. class LoadList {
  120.   final hours;
  121.   final minutes;
  122.   LoadList(this.hours, this.minutes);
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement