Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:rezervisanje/globals.dart' as globals;
- import 'dart:async';
- import 'package:cloud_firestore/cloud_firestore.dart';
- class ReserveTable extends StatefulWidget {
- @override
- _ReserveTableState createState() => _ReserveTableState();
- }
- class _ReserveTableState extends State<ReserveTable> {
- var sum;
- var step = 0;
- var hours = 0;
- var minutes = 0;
- DateTime times;
- final List<LoadList> terminlist = new List();
- final List<LoadList> items = new List();
- final formKey = GlobalKey<FormState>();
- Future<int> firebaseQuery;
- @override
- void initState() {
- super.initState();
- firebaseQuery = Firestore.instance
- .collection('salons')
- .document(globals.salonkey)
- .get()
- .then((document) {
- setState(() {
- globals.shiftstart = document.data['firstshiftstart'];
- globals.shiftend = document.data['firstshiftend'];
- });
- });
- }
- @override
- Widget build(BuildContext context) {
- if (globals.day == null) {
- globals.day = DateTime(
- DateTime.now().year, DateTime.now().month, DateTime.now().day);
- }
- times = globals.day.add(new Duration(days: -1));
- new FutureBuilder(
- future: firebaseQuery,
- builder: (context, snapshot) {
- if (snapshot.hasError) {
- print("snapErr");//not getting printed
- return new Text("${snapshot.error}");
- } else
- items.clear();
- print("SHIFTEND " + globals.shiftend.toString());//not getting printed
- },
- );
- new StreamBuilder<QuerySnapshot>(
- stream: Firestore.instance
- .collection('termins')
- .where('time', isLessThanOrEqualTo: globals.day)
- .where('time', isGreaterThanOrEqualTo: times)
- .where('employeeID', isEqualTo: globals.employeeID)
- .snapshots(),
- builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
- print("2");//not getting printed
- if (!snapshot.hasData)
- return const Text('Connecting...');
- else {
- print('3');//not getting printed
- sum = snapshot.data.documents.length;
- for (int i = 0; i < sum; i++) {
- DocumentSnapshot items = snapshot.data.documents[i];
- DateTime date = items['time'];
- terminlist.add(new LoadList(date.hour, date.minute));
- }
- }
- });
- int div =
- ((globals.shiftend - globals.shiftstart) * 60 / globals.requiredtime)
- .round();
- hours = globals.shiftstart;
- for (var i = 0; i < div; i++) {
- if (minutes == 60) {
- minutes = 0;
- hours = hours + 1;
- }
- items.add(new LoadList(hours, minutes));
- minutes += globals.requiredtime;
- }
- return new Scaffold(
- appBar: new AppBar(
- title:
- new Text(globals.employee == "" ? "Reserve" : globals.employee),
- backgroundColor: Colors.deepOrange,
- ),
- drawer: new Drawer(
- child: new ListView(children: <Widget>[
- new ListTile(
- title: new Text("Close"),
- trailing: new Icon(Icons.arrow_upward),
- onTap: () {
- Navigator.of(context).pop();
- })
- ])),
- body: Card(
- child: Padding(
- padding: EdgeInsets.all(8.0),
- child: Form(
- key: formKey,
- child: new ListView.builder(
- scrollDirection: Axis.vertical,
- itemCount: items.length,
- itemBuilder: (context, index) {
- print(sum);//only this is getting printed,its null
- })),
- )));
- }
- }
- class LoadList {
- final hours;
- final minutes;
- LoadList(this.hours, this.minutes);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement