Skip to content

Commit

Permalink
Revert "display tags in store #15, close store closes #14."
Browse files Browse the repository at this point in the history
  • Loading branch information
zvikarp authored May 1, 2019
1 parent c6a5930 commit 0e42f42
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 235 deletions.
5 changes: 2 additions & 3 deletions lib/dialogs/block.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:io';

import 'package:flutter/material.dart';

import 'package:cup_and_soup/widgets/core/dialog.dart';
import 'package:cup_and_soup/utils/dateTime.dart';

Expand All @@ -19,13 +18,13 @@ class BlockDialog extends StatelessWidget {

if (type == "closed") {
return Text(
"The app is closed until " + dateTimeUtil.date(storeStatus["openingDate"].toDate()) + " " + dateTimeUtil.time(storeStatus["openingDate"].toDate()),
"the app is closed until" + dateTimeUtil.date(storeStatus["openingDate"]) + " " + dateTimeUtil.time(storeStatus["openingDate"]),
textAlign: TextAlign.center,
);}
else
if (type == "disabled") {
return Text(
"Your account is temporarily blocked. please contact a admin to unlock your account.",
"Your account is temporarily blocked. please contact a admin to unlock your account.", //do me
textAlign: TextAlign.center,
);}
else {
Expand Down
245 changes: 124 additions & 121 deletions lib/dialogs/closeStore.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,91 @@
import 'package:flutter/material.dart';

import 'package:cup_and_soup/utils/dateTime.dart';
import 'package:flutter/material.dart';
import 'package:cup_and_soup/services/cloudFirestore.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cup_and_soup/widgets/core/dialog.dart';
import 'package:cup_and_soup/widgets/core/divider.dart';
import 'package:cup_and_soup/widgets/core/button.dart';

class CloseStoreDialog extends StatefulWidget {

@override
_CloseStoreDialogState createState() => _CloseStoreDialogState();
}

class _CloseStoreDialogState extends State<CloseStoreDialog> {
DateTime _openDateTime = DateTime.now();
DateTime _closeDateTime = DateTime.now();
DateTime _closeDateTime= DateTime.now();
final Firestore _storeStat = Firestore.instance;

Widget _actionSection(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
ButtonWidget(
text: "No",
onPressed: () {
Navigator.pop(context, false);
},
primary: false,
size: "small",
),
ButtonWidget(
text: "Yes",
onPressed: () {
cloudFirestoreService.updateStoreStatus(_openDateTime, _closeDateTime);
Navigator.pop(context, true);
},
// primary: false,
size: "small",
),
],
);
}



Widget _openFromWidget(BuildContext context) {
return
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"opening date: ",
style: TextStyle(
fontFamily: "PrimaryFont",
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
GestureDetector(
onTap: () => _openDateSelector(context),
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.black54, width: 1))),
child: Text(dateTimeUtil.date(_openDateTime)),
),
),
GestureDetector(
onTap: () => _openTimeSelector(context),
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.black54, width: 1))),
child: Text(dateTimeUtil.time(_openDateTime)),
),
),
GestureDetector(
onTap: () {
setState(() {
_openDateTime = DateTime.now().add(Duration(minutes: 5));
});
},
)
],
);
}

void _openDateSelector(BuildContext context) async {
DateTime picked = await showDatePicker(
Expand All @@ -38,8 +110,7 @@ class _CloseStoreDialogState extends State<CloseStoreDialog> {
void _openTimeSelector(BuildContext context) async {
TimeOfDay picked = await showTimePicker(
context: context,
initialTime:
TimeOfDay(hour: _openDateTime.hour, minute: _openDateTime.minute),
initialTime: TimeOfDay(hour: _openDateTime.hour, minute: _openDateTime.minute),
);
if (picked != null) {
setState(() {
Expand All @@ -54,7 +125,7 @@ class _CloseStoreDialogState extends State<CloseStoreDialog> {
}
}

void _closeDateSelector(BuildContext context) async {
void _closeDateSelector(BuildContext context) async {
DateTime picked = await showDatePicker(
context: context,
initialDate: _closeDateTime,
Expand All @@ -77,8 +148,7 @@ class _CloseStoreDialogState extends State<CloseStoreDialog> {
void _closeTimeSelector(BuildContext context) async {
TimeOfDay picked = await showTimePicker(
context: context,
initialTime:
TimeOfDay(hour: _closeDateTime.hour, minute: _closeDateTime.minute),
initialTime: TimeOfDay(hour: _closeDateTime.hour, minute: _closeDateTime.minute),
);
if (picked != null) {
setState(() {
Expand All @@ -93,127 +163,60 @@ class _CloseStoreDialogState extends State<CloseStoreDialog> {
}
}

Widget _actionSection(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
ButtonWidget(
text: "No",
onPressed: () {
Navigator.pop(context, false);
},
primary: false,
size: "small",
),
ButtonWidget(
text: "Yes",
onPressed: () {
cloudFirestoreService.updateStoreStatus(
_openDateTime, _closeDateTime);
Navigator.pop(context, true);
},
size: "small",
),
],
);
}

TableRow _openFromWidget(BuildContext context) {
return TableRow(
children: <Widget>[
Text(
"opening date: ",
style: TextStyle(
fontFamily: "PrimaryFont",
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
GestureDetector(
onTap: () => _openDateSelector(context),
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.black54, width: 1))),
child: Text(dateTimeUtil.date(_openDateTime)),
),
),
Container(),
GestureDetector(
onTap: () => _openTimeSelector(context),
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.black54, width: 1))),
child: Text(dateTimeUtil.time(_openDateTime)),
),
Widget _closeFromWidget(BuildContext context) {
return
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"closing date: ",
style: TextStyle(
fontFamily: "PrimaryFont",
fontSize: 18,
fontWeight: FontWeight.bold,
),
],
);
}

TableRow _closeFromWidget(BuildContext context) {
return TableRow(
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 24),
child: Text(
"closing date: ",
style: TextStyle(
fontFamily: "PrimaryFont",
fontSize: 18,
fontWeight: FontWeight.bold,
),
GestureDetector(
onTap: () => _closeDateSelector(context),
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.black54, width: 1))),
child: Text(dateTimeUtil.date(_closeDateTime)),
),
),
),
GestureDetector(
onTap: () => _closeDateSelector(context),
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.black54, width: 1))),
child: Text(dateTimeUtil.date(_closeDateTime)),
),
),
Container(),
GestureDetector(
onTap: () => _closeTimeSelector(context),
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.black54, width: 1))),
child: Text(dateTimeUtil.time(_closeDateTime)),
GestureDetector(
onTap: () => _closeTimeSelector(context),
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.black54, width: 1))),
child: Text(dateTimeUtil.time(_closeDateTime)),
),
),
),
],
);
GestureDetector(
onTap: () {
setState(() {
_openDateTime = DateTime.now().add(Duration(minutes: 5));
});
},
)
],
);
}

@override
Widget build(BuildContext context) {
return DialogWidget(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
children: <Widget>[
Icon(Icons.warning),
Table(
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
columnWidths: {
0: FractionColumnWidth(.4),
1: FractionColumnWidth(.25),
2: FractionColumnWidth(.1),
3: FractionColumnWidth(.25)
},
children: <TableRow>[
_closeFromWidget(context),
_openFromWidget(context),
],
),
DividerWidget(),
_actionSection(context),
],
),
child: Column(
children: <Widget>[
Icon(Icons.warning),
_closeFromWidget(context),
_openFromWidget(context),
DividerWidget(),
_actionSection(context),
],
));
}
}
}
36 changes: 15 additions & 21 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import 'package:flutter/material.dart';

import 'package:cup_and_soup/dialogs/block.dart';
import 'package:cup_and_soup/utils/transparentRoute.dart';
import 'package:cup_and_soup/widgets/core/snackbar.dart';
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

import 'package:cup_and_soup/pages/home/insider.dart';
import 'package:cup_and_soup/pages/home/store.dart';
import 'package:cup_and_soup/pages/home/account.dart';
import 'package:cup_and_soup/pages/home/scanner.dart';
import 'package:cup_and_soup/pages/home/admin.dart';
import 'package:cup_and_soup/widgets/home/navigationBar.dart';
import 'package:cup_and_soup/services/auth.dart';
import 'package:cup_and_soup/services/cloudFirestore.dart';

class HomePage extends StatefulWidget {
Expand Down Expand Up @@ -62,27 +64,19 @@ class _HomePageState extends State<HomePage> {
if (userData['disabled']) {
Navigator.of(context).push(
TransparentRoute(
builder: (BuildContext context) => BlockDialog(
type: "disabled",
),
builder: (BuildContext context) => BlockDialog(type: "disabled",),
),
);
}
var storeStatus = await cloudFirestoreService.loadStoreStatus();
print(DateTime.now());
print(storeStatus['closeingDate'].toDate());
if (DateTime.now().isAfter(storeStatus['closeingDate'].toDate()) &&
DateTime.now().isBefore(storeStatus['openingDate'].toDate())) {
if (_roles.contains("admin")) {
SnackbarWidget.infoBar(
context, "The store is closed!");
} else {
Navigator.of(context).push(
TransparentRoute(
builder: (BuildContext context) =>
BlockDialog(type: "closed", storeStatus: storeStatus),
),
);
final Firestore _storeStat = Firestore.instance;
DateTime _openDateTime;
var storeStatus = await cloudFirestoreService.loadStoreStatus();
if( (storeStatus['closeingDate'].toDate() < DateTime.now()) && (storeStatus['openingDate'].toDate() > DateTime.now())) {
Navigator.of(context).push(
TransparentRoute(
builder: (BuildContext context) => BlockDialog(type: "closed", storeStatus: storeStatus),
),
);

}
}
}
Expand Down
Loading

0 comments on commit 0e42f42

Please sign in to comment.