From 1613bbc98cd2a3e4aecc4fcacbdf86bef2a6ac9c Mon Sep 17 00:00:00 2001 From: Abdullah Ahmed Date: Sun, 19 Jun 2022 22:55:23 -0400 Subject: [PATCH 1/4] Created AddaProduct Screeen --- gro_sense/lib/screens/add_product.dart | 323 ++++++++++++++++++ gro_sense/lib/screens/dashboard.dart | 6 +- .../lib/screens/edit_profile_screen.dart | 10 + gro_sense/lib/screens/screen_login.dart | 2 + gro_sense/pubspec.lock | 18 +- gro_sense/pubspec.yaml | 2 + 6 files changed, 351 insertions(+), 10 deletions(-) create mode 100644 gro_sense/lib/screens/add_product.dart diff --git a/gro_sense/lib/screens/add_product.dart b/gro_sense/lib/screens/add_product.dart new file mode 100644 index 0000000..2a48945 --- /dev/null +++ b/gro_sense/lib/screens/add_product.dart @@ -0,0 +1,323 @@ +import 'dart:io'; +import 'package:fluttertoast/fluttertoast.dart'; +import 'package:gro_sense/model/user_model.dart'; +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:flutter/material.dart'; +import 'package:gro_sense/screens/dashboard.dart'; +import 'package:intl/intl.dart'; +import 'package:gro_sense/screens/screen_login.dart'; +import 'edit_profile_screen.dart'; + +class AddaProductScreen extends StatefulWidget { + const AddaProductScreen({Key? key}) : super(key: key); + + @override + _AddaProductScreenState createState() => _AddaProductScreenState(); + +} + +class _AddaProductScreenState extends State +{ + final _formKey = GlobalKey(); + final auth = FirebaseAuth.instance; + final productNameEditingController = new TextEditingController(); + final expirydateEditingController = new TextEditingController(); + final numberofDaysReminderEditingController = new TextEditingController(); + bool onoroff = false; + var defaultoption = 'reminders off'; + + void toggleSwitch(bool value) + { + + if(onoroff == false) + { + setState(() { + onoroff = true; + defaultoption = 'Reminders On'; + }); + print('Reminders On'); + } + else + { + setState(() { + onoroff = false; + defaultoption = 'Reminders Off'; + }); + print('Reminders Off'); + } + } + + @override + void initState() { + expirydateEditingController.text = ""; + super.initState(); + } + + @override + Widget build(BuildContext context) + { + //Product Name Field + final productNameField= TextFormField + ( + autofocus: false, + controller: productNameEditingController, + keyboardType: TextInputType.text, + validator: (value) { + if(value!.isEmpty) + { + return ("Please enter a product name"); + } + return null; + }, + onSaved: (value) { + productNameEditingController.text = value!; + }, + textInputAction: TextInputAction.next, + decoration: InputDecoration( + prefixIcon: Icon(Icons.account_circle_sharp), + contentPadding: EdgeInsets.fromLTRB(20, 15, 20, 15), + hintText: "Product Name", + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + ), + ); +/* + //Expiry Date Field + showDatePicker( + context: context, + initialDate: DateTime.now(), + firstDate: DateTime.now(), // Required + lastDate: DateTime(2100), // Required + ); + + DateTime selectedDate = new DateTime.now(); + _selectDate(BuildContext context) async { + final DateTime? picked = await showDatePicker( + context: context, + initialDate: selectedDate, + firstDate: DateTime(1950), + lastDate: DateTime(2050), + cancelText: 'Cancel', + confirmText: 'Ok', + ); + if (picked != null && picked != selectedDate) + setState(() { + selectedDate = picked; + } + ); + } */ + + //No of Days before Expiry - Reminder + final numberofDaysReminder= TextFormField + ( + autofocus: false, + controller: numberofDaysReminderEditingController, + keyboardType: TextInputType.text, + validator: (value) { + if(value!.isEmpty) + { + return ("Please enter a value"); + } + return null; + }, + onSaved: (value) { + productNameEditingController.text = value!; + }, + textInputAction: TextInputAction.next, + decoration: InputDecoration( + prefixIcon: Icon(Icons.account_circle_sharp), + contentPadding: EdgeInsets.fromLTRB(20, 15, 20, 15), + hintText: "Get reminder - No of days before expiry", + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + ), + ); + + final submitButton = Material( + elevation: 5, + borderRadius: BorderRadius.circular(30), + color: Colors.green[400], + /* child: MaterialButton( + padding: EdgeInsets.fromLTRB(20, 15, 20, 15), + minWidth: MediaQuery + .of(context) + .size + .width, + onPressed: () { + submit(ProductNameEditingController.text, DateTime); + }, */ + child: Text( + "Submit", + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 20, color: Colors.white, fontWeight: FontWeight.bold), + ) + ); + // ); + + return Scaffold( + appBar: AppBar( + title: Text('Add a Product'), + elevation: 0, + leading: IconButton( + icon: Icon(Icons.arrow_back, color: Colors.white), + onPressed: () { + // passing this to our root + Navigator.of(context).pushReplacement( + MaterialPageRoute(builder: (context) => DashBoardScreen())); + }, + ), + ), + body: Container + ( + width: double.infinity, + height: double.infinity, + decoration: BoxDecoration( + image: DecorationImage( + image: AssetImage("assets/logo.png"), + colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.3), BlendMode.dstATop), + fit: BoxFit.cover, + ), + ), + child: SingleChildScrollView( + child: Container( + color: Colors.transparent, + child: Padding( + padding: const EdgeInsets.all(36.0), + child: Form( + key: _formKey, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SizedBox(height: 20,), + productNameField, + SizedBox(height: 20), + TextField( + controller: expirydateEditingController, //editing controller of this TextField + decoration: InputDecoration( + icon: Icon(Icons.calendar_today), //icon of text field + labelText: "Enter Date" //label text of field + ), + readOnly: true, //set it true, so that user will not able to edit text + onTap: () async { + DateTime? pickedDate = await showDatePicker( + context: context, + initialDate: DateTime.now(), + firstDate: DateTime(2000), //DateTime.now() - not to allow to choose before today. + lastDate: DateTime(2101) + ); + + if(pickedDate != null ){ + print(pickedDate); //pickedDate output format => 2021-03-10 00:00:00.000 + String formattedDate = DateFormat('yyyy-MM-dd').format(pickedDate); + print(formattedDate); //formatted date output using intl package => 2021-03-16 + //you can implement different kind of Date Format here according to your requirement + + setState(() { + expirydateEditingController.text = formattedDate; //set output date to TextField value. + }); + }else{ + print("Date is not selected"); + } + }, + ), + Transform.scale(scale: 2), + Switch + ( + value: onoroff, + onChanged: toggleSwitch, + activeColor: Colors.green, + activeTrackColor: Colors.lightGreenAccent[100], + inactiveThumbColor: Colors.grey[800], + inactiveTrackColor: Colors.grey[500], + ), + SizedBox(height: 15), + Text('$defaultoption', style: TextStyle(fontSize: 20),), + SizedBox(height: 20), + numberofDaysReminder, + SizedBox(height: 20), + submitButton, + ]), + ), + ), + ), + ), + ), + ); + }//Widget Build +/* + void submit(String productName, DateTime selectedDate) async { + if (_formKey.currentState!.validate()) { + try { + await auth + .createUserWithEmailAndPassword(email: email, password: password) + + .then((uid) => + { + Fluttertoast.showToast(msg: "signup Successful"), + Navigator.of(context).pushReplacement( + MaterialPageRoute(builder: (context) => DashBoardScreen())) + }) + .then((value) => {postDetailsToFirestore()}) + .catchError((e) { + Fluttertoast.showToast(msg: e!.message); + }); + } on FirebaseAuthException catch (error) { + switch (error.code) { + case "invalid-email": + errorMessage = "Your email address appears to be malformed."; + break; + case "wrong-password": + errorMessage = "Your password is wrong."; + break; + case "user-not-found": + errorMessage = "User with this email doesn't exist."; + break; + case "user-disabled": + errorMessage = "User with this email has been disabled."; + break; + case "too-many-requests": + errorMessage = "Too many requests"; + break; + case "operation-not-allowed": + errorMessage = "Signing in with Email and Password is not enabled."; + break; + default: + errorMessage = "An undefined Error happened."; + } + Fluttertoast.showToast(msg: errorMessage!); + print(error.code); + } + } + } + + postDetailsToFirestore() async { + // calling our firestore + // calling our user model + // sending these values + + FirebaseFirestore firebaseFirestore = FirebaseFirestore.instance; + User? user = _auth.currentUser; + + UserModel userModel = UserModel(); + + // writing all the values + userModel.email = user!.email; + userModel.uid = user.uid; + userModel.firstName = firstNameEditingController.text; + userModel.secondName = secondNameEditingController.text; + + await firebaseFirestore + .collection("users") + .doc(user.uid) + .set(userModel.toMap()); + Fluttertoast.showToast(msg: "Account created successfully :) "); + + + } +*/ + +} // Class _AddProductScreenState} \ No newline at end of file diff --git a/gro_sense/lib/screens/dashboard.dart b/gro_sense/lib/screens/dashboard.dart index ec5595d..ef580b4 100644 --- a/gro_sense/lib/screens/dashboard.dart +++ b/gro_sense/lib/screens/dashboard.dart @@ -1,5 +1,6 @@ import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; +import 'package:gro_sense/screens/add_product.dart'; import 'edit_profile_screen.dart'; @@ -25,7 +26,10 @@ class _DashBoardScreenState extends State { elevation: 5.0, icon: const Icon(Icons.add), label: const Text('Add'), - onPressed: () {}, + onPressed: () { + Navigator.of(context).pushReplacement( + MaterialPageRoute(builder: (context) => AddaProductScreen())); + }, ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, diff --git a/gro_sense/lib/screens/edit_profile_screen.dart b/gro_sense/lib/screens/edit_profile_screen.dart index 947c519..297e99c 100644 --- a/gro_sense/lib/screens/edit_profile_screen.dart +++ b/gro_sense/lib/screens/edit_profile_screen.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:gro_sense/screens/dashboard.dart'; import 'package:gro_sense/screens/screen_login.dart'; +import 'package:gro_sense/screens/dashboard.dart'; class EditProfileScreen extends StatelessWidget{ @@ -9,6 +10,14 @@ Widget build(BuildContext context){ return Scaffold( appBar: AppBar( title: Text('Settings'), + leading: IconButton( + icon: Icon(Icons.arrow_back, color: Colors.white), + onPressed: () { + // passing this to our root + Navigator.of(context).pushReplacement( + MaterialPageRoute(builder: (context) => DashBoardScreen())); + }, + ), ), body: Container( child: Drawer( @@ -35,6 +44,7 @@ Widget build(BuildContext context){ onTap: (){ Navigator.of(context).pushReplacement( MaterialPageRoute(builder: (context) => LoginScreen())); + },), ], ) diff --git a/gro_sense/lib/screens/screen_login.dart b/gro_sense/lib/screens/screen_login.dart index a707626..4e712de 100644 --- a/gro_sense/lib/screens/screen_login.dart +++ b/gro_sense/lib/screens/screen_login.dart @@ -11,6 +11,8 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; import 'package:gro_sense/screens/reset_password_screen.dart'; +import 'package:gro_sense/screens/add_product.dart'; + class LoginScreen extends StatefulWidget { const LoginScreen({Key? key}) : super(key: key); diff --git a/gro_sense/pubspec.lock b/gro_sense/pubspec.lock index 93fdfb7..3413952 100644 --- a/gro_sense/pubspec.lock +++ b/gro_sense/pubspec.lock @@ -49,14 +49,14 @@ packages: name: cloud_firestore_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "5.5.7" + version: "5.5.8" cloud_firestore_web: dependency: transitive description: name: cloud_firestore_web url: "https://pub.dartlang.org" source: hosted - version: "2.6.16" + version: "2.6.17" collection: dependency: transitive description: @@ -91,42 +91,42 @@ packages: name: firebase_auth url: "https://pub.dartlang.org" source: hosted - version: "3.3.19" + version: "3.3.20" firebase_auth_platform_interface: dependency: transitive description: name: firebase_auth_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "6.2.7" + version: "6.2.8" firebase_auth_web: dependency: transitive description: name: firebase_auth_web url: "https://pub.dartlang.org" source: hosted - version: "3.3.16" + version: "3.3.17" firebase_core: dependency: "direct main" description: name: firebase_core url: "https://pub.dartlang.org" source: hosted - version: "1.17.1" + version: "1.18.0" firebase_core_platform_interface: dependency: transitive description: name: firebase_core_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "4.4.0" + version: "4.4.1" firebase_core_web: dependency: transitive description: name: firebase_core_web url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" + version: "1.6.5" flutter: dependency: "direct main" description: flutter @@ -269,7 +269,7 @@ packages: source: hosted version: "4.0.1" intl: - dependency: transitive + dependency: "direct main" description: name: intl url: "https://pub.dartlang.org" diff --git a/gro_sense/pubspec.yaml b/gro_sense/pubspec.yaml index 0889d83..82b9792 100644 --- a/gro_sense/pubspec.yaml +++ b/gro_sense/pubspec.yaml @@ -27,6 +27,7 @@ dependencies: google_sign_in: ^5.0.3 flutter: sdk: flutter + intl: ^0.17.0 fluttertoast: ^8.0.8 provider: ^5.0.0 flutter_facebook_auth: ^3.5.1 @@ -43,6 +44,7 @@ dev_dependencies: + # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec From 668a70808d7931b06f1e53dd945e61e90eda0a6e Mon Sep 17 00:00:00 2001 From: Abdullah Ahmed Date: Sun, 19 Jun 2022 23:10:20 -0400 Subject: [PATCH 2/4] Created AddaProductScreen --- gro_sense/lib/screens/add_product.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gro_sense/lib/screens/add_product.dart b/gro_sense/lib/screens/add_product.dart index 2a48945..f1ce9d8 100644 --- a/gro_sense/lib/screens/add_product.dart +++ b/gro_sense/lib/screens/add_product.dart @@ -15,7 +15,7 @@ class AddaProductScreen extends StatefulWidget { _AddaProductScreenState createState() => _AddaProductScreenState(); } - +//ghjk class _AddaProductScreenState extends State { final _formKey = GlobalKey(); From 5fbb26f11702a62ca593443aa7e7e84f4008617b Mon Sep 17 00:00:00 2001 From: Abdullah Ahmed Date: Fri, 24 Jun 2022 11:35:41 -0400 Subject: [PATCH 3/4] Added integration to firebase --- gro_sense/lib/Model/product_details.dart | 14 ++ gro_sense/lib/Model/user_model.dart | 18 ++- gro_sense/lib/screens/add_product.dart | 151 +++++++----------- .../lib/screens/registration_screen.dart | 5 +- gro_sense/pubspec.lock | 118 +++++++++++++- gro_sense/pubspec.yaml | 5 +- 6 files changed, 210 insertions(+), 101 deletions(-) create mode 100644 gro_sense/lib/Model/product_details.dart diff --git a/gro_sense/lib/Model/product_details.dart b/gro_sense/lib/Model/product_details.dart new file mode 100644 index 0000000..95ce430 --- /dev/null +++ b/gro_sense/lib/Model/product_details.dart @@ -0,0 +1,14 @@ +import 'dart:ui'; +import 'package:gro_sense/model/user_model.dart'; + +class addprod{ + String? productName; + DateTime? expiryDate; + + addprod(this.productName,this.expiryDate); + + Map toMap() => { + "productName" : productName, + "expiryDate" : expiryDate, + }; +} diff --git a/gro_sense/lib/Model/user_model.dart b/gro_sense/lib/Model/user_model.dart index 6dd70ab..a677620 100644 --- a/gro_sense/lib/Model/user_model.dart +++ b/gro_sense/lib/Model/user_model.dart @@ -1,3 +1,4 @@ +import 'package:gro_sense/model/product_details.dart'; class UserModel { String? uid; String? email; @@ -13,10 +14,9 @@ class UserModel { email: map['email'], firstName: map['firstName'], secondName: map['secondName'], - emailVerified: map['emailVerified'] + emailVerified: map['emailVerified'], ); } - // sending data to our server Map toMap() { return { @@ -24,7 +24,19 @@ class UserModel { 'email': email, 'firstName': firstName, 'secondName': secondName, - 'emailVerified': emailVerified + 'emailVerified': emailVerified, + }; + } + + +} +mixin Userclass implements addprod { + + List addproduct = []; +//send data to database + Map toMap() { + return { + 'addprod': addprod, }; } } \ No newline at end of file diff --git a/gro_sense/lib/screens/add_product.dart b/gro_sense/lib/screens/add_product.dart index f1ce9d8..b393ff4 100644 --- a/gro_sense/lib/screens/add_product.dart +++ b/gro_sense/lib/screens/add_product.dart @@ -1,11 +1,18 @@ +import 'dart:ffi'; import 'dart:io'; +import 'package:flutter/services.dart'; import 'package:fluttertoast/fluttertoast.dart'; +import 'package:gro_sense/Model/product_details.dart'; import 'package:gro_sense/model/user_model.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:firebase_core/firebase_core.dart'; import 'package:gro_sense/screens/dashboard.dart'; import 'package:intl/intl.dart'; import 'package:gro_sense/screens/screen_login.dart'; +import 'package:gro_sense/screens/home_screen.dart'; +import 'package:flutter/material.dart'; import 'edit_profile_screen.dart'; class AddaProductScreen extends StatefulWidget { @@ -15,7 +22,7 @@ class AddaProductScreen extends StatefulWidget { _AddaProductScreenState createState() => _AddaProductScreenState(); } -//ghjk + class _AddaProductScreenState extends State { final _formKey = GlobalKey(); @@ -24,8 +31,8 @@ class _AddaProductScreenState extends State final expirydateEditingController = new TextEditingController(); final numberofDaysReminderEditingController = new TextEditingController(); bool onoroff = false; - var defaultoption = 'reminders off'; - + var defaultoption = 'Reminders Off'; + late DateTime? pickedDate= DateTime.now(); void toggleSwitch(bool value) { @@ -113,7 +120,13 @@ class _AddaProductScreenState extends State ( autofocus: false, controller: numberofDaysReminderEditingController, - keyboardType: TextInputType.text, + keyboardType: TextInputType.number, + inputFormatters: [ + FilteringTextInputFormatter.digitsOnly + ], + textInputAction: TextInputAction.next,// Only numbers can be entered + onSaved: (value) { + numberofDaysReminderEditingController.text = value!;}, validator: (value) { if(value!.isEmpty) { @@ -121,41 +134,39 @@ class _AddaProductScreenState extends State } return null; }, - onSaved: (value) { - productNameEditingController.text = value!; - }, - textInputAction: TextInputAction.next, decoration: InputDecoration( prefixIcon: Icon(Icons.account_circle_sharp), - contentPadding: EdgeInsets.fromLTRB(20, 15, 20, 15), - hintText: "Get reminder - No of days before expiry", + contentPadding: EdgeInsets.fromLTRB(20, 20, 20, 20), + hintText: "No of days for Reminder", border: OutlineInputBorder( borderRadius: BorderRadius.circular(10), + ), ), ); + final submitButton = Material( elevation: 5, - borderRadius: BorderRadius.circular(30), + borderRadius: BorderRadius.circular(500), color: Colors.green[400], - /* child: MaterialButton( + child: MaterialButton( padding: EdgeInsets.fromLTRB(20, 15, 20, 15), minWidth: MediaQuery .of(context) .size .width, onPressed: () { - submit(ProductNameEditingController.text, DateTime); - }, */ + addDataUp(); + }, child: Text( "Submit", textAlign: TextAlign.center, style: TextStyle( - fontSize: 20, color: Colors.white, fontWeight: FontWeight.bold), - ) - ); - // ); + fontSize: 25, color: Colors.white, fontWeight: FontWeight.bold, decorationThickness: 40), + ), + ), + ); return Scaffold( appBar: AppBar( @@ -191,7 +202,7 @@ class _AddaProductScreenState extends State child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, - children: [ + children:[ SizedBox(height: 20,), productNameField, SizedBox(height: 20), @@ -203,19 +214,19 @@ class _AddaProductScreenState extends State ), readOnly: true, //set it true, so that user will not able to edit text onTap: () async { - DateTime? pickedDate = await showDatePicker( + DateTime? pickedDate = await showDatePicker( context: context, initialDate: DateTime.now(), - firstDate: DateTime(2000), //DateTime.now() - not to allow to choose before today. - lastDate: DateTime(2101) + firstDate: DateTime.now(), //DateTime.now() - not to allow to choose before today. + lastDate: DateTime(2101), ); - if(pickedDate != null ){ print(pickedDate); //pickedDate output format => 2021-03-10 00:00:00.000 String formattedDate = DateFormat('yyyy-MM-dd').format(pickedDate); + // int numberofdaysreminder = int.parse(numberofDaysReminderEditingController.text); print(formattedDate); //formatted date output using intl package => 2021-03-16 //you can implement different kind of Date Format here according to your requirement - + // var reminderdate = pickedDate.subtract(Duration(days:- numberofdaysreminder )); setState(() { expirydateEditingController.text = formattedDate; //set output date to TextField value. }); @@ -223,7 +234,7 @@ class _AddaProductScreenState extends State print("Date is not selected"); } }, - ), + ), Transform.scale(scale: 2), Switch ( @@ -234,11 +245,16 @@ class _AddaProductScreenState extends State inactiveThumbColor: Colors.grey[800], inactiveTrackColor: Colors.grey[500], ), - SizedBox(height: 15), - Text('$defaultoption', style: TextStyle(fontSize: 20),), - SizedBox(height: 20), - numberofDaysReminder, + SizedBox(height: 1), + Text('$defaultoption', + style: TextStyle(fontSize: 20),), SizedBox(height: 20), + if (onoroff == true)... + [ + SizedBox(height: 20), + numberofDaysReminder, + ], + SizedBox(height: 30), submitButton, ]), ), @@ -248,76 +264,27 @@ class _AddaProductScreenState extends State ), ); }//Widget Build -/* - void submit(String productName, DateTime selectedDate) async { - if (_formKey.currentState!.validate()) { - try { - await auth - .createUserWithEmailAndPassword(email: email, password: password) - .then((uid) => - { - Fluttertoast.showToast(msg: "signup Successful"), + void addDataUp() async { + Fluttertoast.showToast(msg: "Adding Products Successful"); Navigator.of(context).pushReplacement( MaterialPageRoute(builder: (context) => DashBoardScreen())) - }) - .then((value) => {postDetailsToFirestore()}) - .catchError((e) { - Fluttertoast.showToast(msg: e!.message); - }); - } on FirebaseAuthException catch (error) { - switch (error.code) { - case "invalid-email": - errorMessage = "Your email address appears to be malformed."; - break; - case "wrong-password": - errorMessage = "Your password is wrong."; - break; - case "user-not-found": - errorMessage = "User with this email doesn't exist."; - break; - case "user-disabled": - errorMessage = "User with this email has been disabled."; - break; - case "too-many-requests": - errorMessage = "Too many requests"; - break; - case "operation-not-allowed": - errorMessage = "Signing in with Email and Password is not enabled."; - break; - default: - errorMessage = "An undefined Error happened."; - } - Fluttertoast.showToast(msg: errorMessage!); - print(error.code); - } - } + .then((value) => {saveResultToFirebase()}); } - postDetailsToFirestore() async { - // calling our firestore - // calling our user model - // sending these values - - FirebaseFirestore firebaseFirestore = FirebaseFirestore.instance; - User? user = _auth.currentUser; - - UserModel userModel = UserModel(); + saveResultToFirebase() async { + User? currentUser = FirebaseAuth.instance.currentUser; + addprod addPro; - // writing all the values - userModel.email = user!.email; - userModel.uid = user.uid; - userModel.firstName = firstNameEditingController.text; - userModel.secondName = secondNameEditingController.text; - - await firebaseFirestore + addPro = addprod(productNameEditingController.text, pickedDate); + // print(pickedDate); + await FirebaseFirestore.instance .collection("users") - .doc(user.uid) - .set(userModel.toMap()); - Fluttertoast.showToast(msg: "Account created successfully :) "); - + .doc(currentUser!.uid) + .update({ + "addprod": FieldValue.arrayUnion([addPro.toMap()]) + }); } -*/ -} // Class _AddProductScreenState} \ No newline at end of file +} //MAIN CLASS END \ No newline at end of file diff --git a/gro_sense/lib/screens/registration_screen.dart b/gro_sense/lib/screens/registration_screen.dart index 7494bb4..f17ebf9 100644 --- a/gro_sense/lib/screens/registration_screen.dart +++ b/gro_sense/lib/screens/registration_screen.dart @@ -6,7 +6,8 @@ import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:gro_sense/screens/screen_login.dart'; - +import 'package:gro_sense/screens/screen_login.dart'; +import 'package:gro_sense/screens/add_product.dart'; class RegistrationScreen extends StatefulWidget { const RegistrationScreen({Key? key}) : super(key: key); @@ -319,7 +320,7 @@ class _RegistrationScreenState extends State { postDetailsToFirestore() async { // calling our firestore // calling our user model - // sedning these values + // sending these values FirebaseFirestore firebaseFirestore = FirebaseFirestore.instance; User? user = _auth.currentUser; diff --git a/gro_sense/pubspec.lock b/gro_sense/pubspec.lock index 3413952..e522362 100644 --- a/gro_sense/pubspec.lock +++ b/gro_sense/pubspec.lock @@ -1,6 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.1" async: dependency: transitive description: @@ -42,7 +49,7 @@ packages: name: cloud_firestore url: "https://pub.dartlang.org" source: hosted - version: "2.5.4" + version: "3.1.18" cloud_firestore_platform_interface: dependency: transitive description: @@ -78,6 +85,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.5" + dbus: + dependency: transitive + description: + name: dbus + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.5" fake_async: dependency: transitive description: @@ -85,6 +99,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.2" firebase_auth: dependency: "direct main" description: @@ -127,6 +155,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.6.5" + firebase_storage: + dependency: "direct main" + description: + name: firebase_storage + url: "https://pub.dartlang.org" + source: hosted + version: "10.2.18" + firebase_storage_platform_interface: + dependency: transitive + description: + name: firebase_storage_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "4.1.8" + firebase_storage_web: + dependency: transitive + description: + name: firebase_storage_web + url: "https://pub.dartlang.org" + source: hosted + version: "3.2.17" flutter: dependency: "direct main" description: flutter @@ -160,6 +209,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.6.0+2" + flutter_local_notifications: + dependency: "direct main" + description: + name: flutter_local_notifications + url: "https://pub.dartlang.org" + source: hosted + version: "9.6.1" + flutter_local_notifications_linux: + dependency: transitive + description: + name: flutter_local_notifications_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.5.0+1" + flutter_local_notifications_platform_interface: + dependency: transitive + description: + name: flutter_local_notifications_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "5.0.0" flutter_secure_storage: dependency: "direct main" description: @@ -246,7 +316,7 @@ packages: name: google_sign_in_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "2.2.0" google_sign_in_web: dependency: transitive description: @@ -317,6 +387,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "5.0.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" plugin_platform_interface: dependency: transitive description: @@ -324,6 +408,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.4" provider: dependency: "direct main" description: @@ -385,6 +476,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.9" + timezone: + dependency: "direct main" + description: + name: timezone + url: "https://pub.dartlang.org" + source: hosted + version: "0.8.0" twitter_login: dependency: "direct main" description: @@ -406,6 +504,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0+1" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.0" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=2.17.0 <3.0.0" flutter: ">=2.8.0" diff --git a/gro_sense/pubspec.yaml b/gro_sense/pubspec.yaml index 82b9792..aee9c78 100644 --- a/gro_sense/pubspec.yaml +++ b/gro_sense/pubspec.yaml @@ -21,13 +21,16 @@ environment: sdk: ">=2.12.0 <3.0.0" dependencies: - cloud_firestore: ^2.5.1 + cloud_firestore: ^3.1.18 firebase_auth: ^3.1.0 firebase_core: ^1.6.0 google_sign_in: ^5.0.3 + firebase_storage: ^10.2.18 flutter: sdk: flutter intl: ^0.17.0 + flutter_local_notifications: ^9.3.2 + timezone: ^0.8.0 fluttertoast: ^8.0.8 provider: ^5.0.0 flutter_facebook_auth: ^3.5.1 From e3d09232fe7ac39d967f18363c9e420cf691f4c1 Mon Sep 17 00:00:00 2001 From: Abdullah Ahmed Date: Sun, 26 Jun 2022 14:35:57 -0400 Subject: [PATCH 4/4] Reminder Date Working --- gro_sense/lib/screens/add_product.dart | 49 ++++++++------------------ 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/gro_sense/lib/screens/add_product.dart b/gro_sense/lib/screens/add_product.dart index b393ff4..44b259c 100644 --- a/gro_sense/lib/screens/add_product.dart +++ b/gro_sense/lib/screens/add_product.dart @@ -32,7 +32,10 @@ class _AddaProductScreenState extends State final numberofDaysReminderEditingController = new TextEditingController(); bool onoroff = false; var defaultoption = 'Reminders Off'; - late DateTime? pickedDate= DateTime.now(); + DateTime? pickedDate; + int? numberofdaysreminder; + DateTime? reminderdate; + void toggleSwitch(bool value) { @@ -89,31 +92,7 @@ class _AddaProductScreenState extends State ), ), ); -/* - //Expiry Date Field - showDatePicker( - context: context, - initialDate: DateTime.now(), - firstDate: DateTime.now(), // Required - lastDate: DateTime(2100), // Required - ); - DateTime selectedDate = new DateTime.now(); - _selectDate(BuildContext context) async { - final DateTime? picked = await showDatePicker( - context: context, - initialDate: selectedDate, - firstDate: DateTime(1950), - lastDate: DateTime(2050), - cancelText: 'Cancel', - confirmText: 'Ok', - ); - if (picked != null && picked != selectedDate) - setState(() { - selectedDate = picked; - } - ); - } */ //No of Days before Expiry - Reminder final numberofDaysReminder= TextFormField @@ -214,7 +193,7 @@ class _AddaProductScreenState extends State ), readOnly: true, //set it true, so that user will not able to edit text onTap: () async { - DateTime? pickedDate = await showDatePicker( + pickedDate = await showDatePicker( context: context, initialDate: DateTime.now(), firstDate: DateTime.now(), //DateTime.now() - not to allow to choose before today. @@ -222,17 +201,19 @@ class _AddaProductScreenState extends State ); if(pickedDate != null ){ print(pickedDate); //pickedDate output format => 2021-03-10 00:00:00.000 - String formattedDate = DateFormat('yyyy-MM-dd').format(pickedDate); - // int numberofdaysreminder = int.parse(numberofDaysReminderEditingController.text); - print(formattedDate); //formatted date output using intl package => 2021-03-16 + + // numberofdaysreminder = int.tryParse(numberofDaysReminderEditingController.text); + //you can implement different kind of Date Format here according to your requirement - // var reminderdate = pickedDate.subtract(Duration(days:- numberofdaysreminder )); - setState(() { - expirydateEditingController.text = formattedDate; //set output date to TextField value. - }); + // reminderdate = pickedDate?.subtract(Duration(days:- numberofdaysreminder!)); }else{ print("Date is not selected"); } + setState(() { + String formattedDate = DateFormat('yyyy-MM-dd').format(pickedDate!); + print(formattedDate); //formatted date output using intl package => 2021-03-16 + expirydateEditingController.text = formattedDate; //set output date to TextField value. + }); }, ), Transform.scale(scale: 2), @@ -282,7 +263,7 @@ class _AddaProductScreenState extends State .collection("users") .doc(currentUser!.uid) .update({ - "addprod": FieldValue.arrayUnion([addPro.toMap()]) + "Add Product": FieldValue.arrayUnion([addPro.toMap()]) }); }