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_datetime_picker/flutter_datetime_picker.dart';
import 'package:ifarm/AB/Utils/Colors.dart';
......@@ -10,11 +11,27 @@ class FoodBucketSchedule extends StatefulWidget {
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> {
@override
void initState() {
buckets.clear();
print(buckets);
// TODO: implement initState
super.initState();
}
@override
Widget build(BuildContext context) {
final Stream<QuerySnapshot> bucketref =
FirebaseFirestore.instance.collection('buckets').snapshots();
return Padding(
padding: const EdgeInsets.all(25),
child: Column(
......@@ -50,44 +67,234 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
child: TextFormField(
readOnly: true,
onTap: () {
DatePicker.showDateTimePicker(context,
DatePicker.showDatePicker(context,
showTitleActions: true,
minTime: DateTime(2022, 11, 5),
maxTime: DateTime(2019, 6, 7), onChanged: (date) {
print(
'change ${DateFormat('yyyy-MM-dd kk:mm').format(date)}');
minTime: DateTime(2022, 1, 1),
maxTime: DateTime(2030, 12, 31), onChanged: (date) {
print('change ${DateFormat('yyyy-MM-dd').format(date)}');
}, onConfirm: (date) {
print(
'confirm ${DateFormat('yyyy-MM-dd kk:mm').format(date)}');
print('confirm ${DateFormat('yyyy-MM-dd').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(() {
dateandtime.text =
DateFormat('yyyy-MM-dd – kk:mm').format(date);
timeController.text = DateFormat('kk:mm').format(time);
});
}, currentTime: DateTime.now(), locale: LocaleType.en);
},
controller: dateandtime,
controller: timeController,
style:
const TextStyle(color: Color.fromARGB(255, 255, 255, 255)),
cursorColor: const Color.fromARGB(255, 0, 0, 0),
decoration: const InputDecoration(
hintText: "Pick Date and Time",
suffixIcon: Icon(
Icons.timer,
color: Colors.white,
),
hintText: "Pick Time",
border: InputBorder.none,
hintStyle:
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(
child: ListView.builder(
itemCount: 2,
child: dateList.isEmpty
? const Center(
child: Text(
"No Scheduled Data",
style: TextStyle(color: subtextColor),
),
)
: 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 {
const NotificationDetails(
android: AndroidNotificationDetails(
'main_channel', 'Main Channel', 'Main channel notifications',
playSound: false,
importance: Importance.max,
priority: Priority.max,
icon: '@drawable/ifarm_icon_blue'),
......
......@@ -25,7 +25,7 @@ class MyThemes {
primaryColor: backgroundColor,
brightness: Brightness.light,
scaffoldBackgroundColor: backgroundColor,
floatingActionButtonTheme: FloatingActionButtonThemeData(
floatingActionButtonTheme: const FloatingActionButtonThemeData(
backgroundColor: naviconUnselectedColor),
appBarTheme:
const AppBarTheme(backgroundColor: backgroundColor, elevation: 0),
......@@ -37,7 +37,7 @@ class MyThemes {
static final darkTheme = ThemeData(
primaryColor: backgroundColorDark,
brightness: Brightness.dark,
floatingActionButtonTheme: FloatingActionButtonThemeData(
floatingActionButtonTheme: const FloatingActionButtonThemeData(
backgroundColor: naviconUnselectedColorDark),
appBarTheme:
const AppBarTheme(backgroundColor: backgroundColorDark, elevation: 0),
......
......@@ -346,7 +346,7 @@ packages:
source: hosted
version: "3.1.3"
intl:
dependency: transitive
dependency: "direct main"
description:
name: intl
url: "https://pub.dartlang.org"
......
......@@ -36,7 +36,7 @@ dependencies:
flutter_native_timezone: ^2.0.0
cron: ^0.5.0
flutter_datetime_picker: ^1.5.1
intl: ^0.15.7
intl: ^0.17.0
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