Commit d0dda92c authored by ayodyabanuka's avatar ayodyabanuka

create schedule screen

parent 00a24151
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:ifarm/AB/Utils/Colors.dart'; import 'package:ifarm/AB/Utils/Colors.dart';
...@@ -10,11 +11,27 @@ class FoodBucketSchedule extends StatefulWidget { ...@@ -10,11 +11,27 @@ class FoodBucketSchedule extends StatefulWidget {
State<FoodBucketSchedule> createState() => _FoodBucketScheduleState(); State<FoodBucketSchedule> createState() => _FoodBucketScheduleState();
} }
TextEditingController dateandtime = TextEditingController(); TextEditingController dateController = TextEditingController();
TextEditingController timeController = TextEditingController();
List dateList = [];
List timeList = [];
List buckets = [];
List bucketsMap = [];
class _FoodBucketScheduleState extends State<FoodBucketSchedule> { class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
@override
void initState() {
buckets.clear();
print(buckets);
// TODO: implement initState
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Stream<QuerySnapshot> bucketref =
FirebaseFirestore.instance.collection('buckets').snapshots();
return Padding( return Padding(
padding: const EdgeInsets.all(25), padding: const EdgeInsets.all(25),
child: Column( child: Column(
...@@ -50,44 +67,234 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> { ...@@ -50,44 +67,234 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
child: TextFormField( child: TextFormField(
readOnly: true, readOnly: true,
onTap: () { onTap: () {
DatePicker.showDateTimePicker(context, DatePicker.showDatePicker(context,
showTitleActions: true, showTitleActions: true,
minTime: DateTime(2022, 11, 5), minTime: DateTime(2022, 1, 1),
maxTime: DateTime(2019, 6, 7), onChanged: (date) { maxTime: DateTime(2030, 12, 31), onChanged: (date) {
print( print('change ${DateFormat('yyyy-MM-dd').format(date)}');
'change ${DateFormat('yyyy-MM-dd kk:mm').format(date)}');
}, onConfirm: (date) { }, onConfirm: (date) {
print( print('confirm ${DateFormat('yyyy-MM-dd').format(date)}');
'confirm ${DateFormat('yyyy-MM-dd kk:mm').format(date)}'); setState(() {
dateController.text =
DateFormat('yyyy-MM-dd').format(date);
});
}, currentTime: DateTime.now(), locale: LocaleType.en);
},
controller: dateController,
style:
const TextStyle(color: Color.fromARGB(255, 255, 255, 255)),
cursorColor: const Color.fromARGB(255, 0, 0, 0),
decoration: const InputDecoration(
suffixIcon: Icon(
Icons.calendar_month,
color: Colors.white,
),
hintText: "Pick Date",
border: InputBorder.none,
hintStyle:
TextStyle(color: Color.fromARGB(255, 255, 255, 255))),
),
),
),
const SizedBox(
height: 10,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15), color: cardColor),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: TextFormField(
readOnly: true,
onTap: () {
DatePicker.showTimePicker(context, showTitleActions: true,
onChanged: (time) {
print('change ${DateFormat('kk:mm').format(time)}');
}, onConfirm: (time) {
print('confirm ${DateFormat('kk:mm').format(time)}');
setState(() { setState(() {
dateandtime.text = timeController.text = DateFormat('kk:mm').format(time);
DateFormat('yyyy-MM-dd – kk:mm').format(date);
}); });
}, currentTime: DateTime.now(), locale: LocaleType.en); }, currentTime: DateTime.now(), locale: LocaleType.en);
}, },
controller: dateandtime, controller: timeController,
style: style:
const TextStyle(color: Color.fromARGB(255, 255, 255, 255)), const TextStyle(color: Color.fromARGB(255, 255, 255, 255)),
cursorColor: const Color.fromARGB(255, 0, 0, 0), cursorColor: const Color.fromARGB(255, 0, 0, 0),
decoration: const InputDecoration( decoration: const InputDecoration(
hintText: "Pick Date and Time", suffixIcon: Icon(
Icons.timer,
color: Colors.white,
),
hintText: "Pick Time",
border: InputBorder.none, border: InputBorder.none,
hintStyle: hintStyle:
TextStyle(color: Color.fromARGB(255, 255, 255, 255))), TextStyle(color: Color.fromARGB(255, 255, 255, 255))),
), ),
), ),
), ),
const SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () {
setState(() {
timeController.clear();
dateController.clear();
});
},
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 10),
decoration: BoxDecoration(
border: Border.all(color: yellowButton),
borderRadius: BorderRadius.circular(10)),
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 5, vertical: 1),
child: Text(
'Cancel',
style: TextStyle(
color: Colors.white, fontFamily: 'poppins'),
),
),
)),
const SizedBox(
width: 10,
),
GestureDetector(
onTap: () {
if (dateController.text.isNotEmpty &&
timeController.text.isNotEmpty) {
setState(() {
dateList.add(dateController.text);
timeList.add(timeController.text);
dateController.clear();
timeController.clear();
});
}
},
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 10),
decoration: BoxDecoration(
color: yellowButton,
borderRadius: BorderRadius.circular(10)),
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 5, vertical: 1),
child: Text(
'Schedule',
style: TextStyle(
fontFamily: 'poppins', color: blacktxtColor),
),
),
)),
],
),
const SizedBox(
height: 20,
),
Row(
children: const [
Text(
"Scheduled List",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18),
),
],
),
const SizedBox(
height: 10,
),
Expanded( Expanded(
child: ListView.builder( child: dateList.isEmpty
itemCount: 2, ? const Center(
itemBuilder: (context, index) { child: Text(
return Container( "No Scheduled Data",
padding: const EdgeInsets.all(15), style: TextStyle(color: subtextColor),
decoration: BoxDecoration( ),
color: cardColor, )
borderRadius: BorderRadius.circular(15)), : ListView.builder(
); itemCount: dateList.length,
})) itemBuilder: (context, index) {
return Container(
margin: const EdgeInsets.symmetric(vertical: 5),
padding: const EdgeInsets.all(15),
decoration: BoxDecoration(
color: cardColor,
borderRadius: BorderRadius.circular(15)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Date: ${dateList[index]} Time: ${timeList[index]}",
style: const TextStyle(color: Colors.white),
),
IconButton(
onPressed: () {
setState(() {
dateList.remove(dateList[index]);
timeList.remove(timeList[index]);
});
},
icon: const Icon(
Icons.delete,
color: Colors.red,
))
],
),
);
})),
Visibility(
visible: true,
child: Container(
height: 0,
child: StreamBuilder<QuerySnapshot>(
stream: bucketref,
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return const Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
snapshot.data.docs.map((DocumentSnapshot document) {
Map a = document.data() as Map<String, dynamic>;
buckets.clear();
bucketsMap.add(a);
for (var i = 0;
i < bucketsMap[0]['Buckets'].length;
i++) {
buckets.add(bucketsMap[0]['Buckets'][i]);
}
print(buckets);
}).toList();
return bucketsMap[0]['Buckets'].isEmpty
? const Center(
child: Text(
'Add bucket',
style: TextStyle(
color: textColor,
fontSize: 20,
fontWeight: FontWeight.bold),
))
: ListView.builder(
itemCount: bucketsMap[0]['Buckets'].length,
itemBuilder: (context, index) {
return Container();
});
},
)),
)
], ],
), ),
); );
......
...@@ -44,7 +44,6 @@ class NotificationService { ...@@ -44,7 +44,6 @@ class NotificationService {
const NotificationDetails( const NotificationDetails(
android: AndroidNotificationDetails( android: AndroidNotificationDetails(
'main_channel', 'Main Channel', 'Main channel notifications', 'main_channel', 'Main Channel', 'Main channel notifications',
playSound: false,
importance: Importance.max, importance: Importance.max,
priority: Priority.max, priority: Priority.max,
icon: '@drawable/ifarm_icon_blue'), icon: '@drawable/ifarm_icon_blue'),
......
...@@ -25,7 +25,7 @@ class MyThemes { ...@@ -25,7 +25,7 @@ class MyThemes {
primaryColor: backgroundColor, primaryColor: backgroundColor,
brightness: Brightness.light, brightness: Brightness.light,
scaffoldBackgroundColor: backgroundColor, scaffoldBackgroundColor: backgroundColor,
floatingActionButtonTheme: FloatingActionButtonThemeData( floatingActionButtonTheme: const FloatingActionButtonThemeData(
backgroundColor: naviconUnselectedColor), backgroundColor: naviconUnselectedColor),
appBarTheme: appBarTheme:
const AppBarTheme(backgroundColor: backgroundColor, elevation: 0), const AppBarTheme(backgroundColor: backgroundColor, elevation: 0),
...@@ -37,7 +37,7 @@ class MyThemes { ...@@ -37,7 +37,7 @@ class MyThemes {
static final darkTheme = ThemeData( static final darkTheme = ThemeData(
primaryColor: backgroundColorDark, primaryColor: backgroundColorDark,
brightness: Brightness.dark, brightness: Brightness.dark,
floatingActionButtonTheme: FloatingActionButtonThemeData( floatingActionButtonTheme: const FloatingActionButtonThemeData(
backgroundColor: naviconUnselectedColorDark), backgroundColor: naviconUnselectedColorDark),
appBarTheme: appBarTheme:
const AppBarTheme(backgroundColor: backgroundColorDark, elevation: 0), const AppBarTheme(backgroundColor: backgroundColorDark, elevation: 0),
......
...@@ -346,7 +346,7 @@ packages: ...@@ -346,7 +346,7 @@ packages:
source: hosted source: hosted
version: "3.1.3" version: "3.1.3"
intl: intl:
dependency: transitive dependency: "direct main"
description: description:
name: intl name: intl
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
......
...@@ -36,7 +36,7 @@ dependencies: ...@@ -36,7 +36,7 @@ dependencies:
flutter_native_timezone: ^2.0.0 flutter_native_timezone: ^2.0.0
cron: ^0.5.0 cron: ^0.5.0
flutter_datetime_picker: ^1.5.1 flutter_datetime_picker: ^1.5.1
intl: ^0.15.7 intl: ^0.17.0
dev_dependencies: dev_dependencies:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment