diff --git a/lib/blocs/FoodDetailPageBloc.dart b/lib/blocs/FoodDetailPageBloc.dart index 453c96c..847cdc8 100644 --- a/lib/blocs/FoodDetailPageBloc.dart +++ b/lib/blocs/FoodDetailPageBloc.dart @@ -30,8 +30,9 @@ class FoodDetailPageBloc with ChangeNotifier { List foodList=[]; - // I dont implemented rating system, so just for good UI showing random value of rates from 0.00 to 5.00 - // I been lazy here. + // I dont implemented rating system, + // so just for good UI, i am showing random value of rates from 0.00 to 5.00, + // I been lazy here XD. var random = new Random(); String rating = "1.00"; diff --git a/lib/blocs/RegisterPageBloc.dart b/lib/blocs/RegisterPageBloc.dart index a399193..d4507d8 100644 --- a/lib/blocs/RegisterPageBloc.dart +++ b/lib/blocs/RegisterPageBloc.dart @@ -15,9 +15,7 @@ */ import 'package:email_validator/email_validator.dart'; -import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/scheduler.dart'; import 'package:food_delivery_app/resourese/auth_methods.dart'; class RegisterPageBloc with ChangeNotifier { diff --git a/lib/resourese/firebase_helper.dart b/lib/resourese/firebase_helper.dart index 9e317e7..25ad1f4 100644 --- a/lib/resourese/firebase_helper.dart +++ b/lib/resourese/firebase_helper.dart @@ -60,7 +60,7 @@ class FirebaseHelper{ ListfoodList = []; await _foodReference.once().then((DataSnapshot snap) { - var keys = snap.value.keys; + var keys = snap.value.keys; var data = snap.value; foodList.clear(); for(var individualKey in keys){ @@ -111,18 +111,18 @@ class FirebaseHelper{ DatabaseReference foodReference = _ordersReference.child(currentUser.uid); await foodReference.once().then((DataSnapshot snap) { - var KEYS = snap.value.keys; - var DATA = snap.value; + var keys = snap.value.keys; + var data = snap.value; requestList.clear(); - for (var individualKey in KEYS) { + for (var individualKey in keys) { Request request =Request( - address: DATA[individualKey]['address'], - name:DATA[individualKey]['name'], - uid:DATA[individualKey]['uid'], - status:DATA[individualKey]['status'], - total:DATA[individualKey]['total'], - foodList:DATA[individualKey]['foodList'], + address:data[individualKey]['address'], + name:data[individualKey]['name'], + uid:data[individualKey]['uid'], + status:data[individualKey]['status'], + total:data[individualKey]['total'], + foodList:data[individualKey]['foodList'], ); requestList.add(request); } diff --git a/lib/screens/CartPage.dart b/lib/screens/CartPage.dart index 96a5ce8..4fa0064 100644 --- a/lib/screens/CartPage.dart +++ b/lib/screens/CartPage.dart @@ -17,9 +17,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:food_delivery_app/blocs/CartPageBloc.dart'; -import 'package:food_delivery_app/models/Food.dart'; -import 'package:food_delivery_app/resourese/databaseSQL.dart'; import 'package:food_delivery_app/utils/universal_variables.dart'; +import 'package:food_delivery_app/widgets/cartitemswidget.dart'; import 'package:provider/provider.dart'; class CartPage extends StatelessWidget { @@ -42,13 +41,12 @@ class CartPageContent extends StatefulWidget { class _CartPageContentState extends State { CartPageBloc cartPageBloc; - TextEditingController nametextcontroller, addresstextcontroller; + TextEditingController nametextcontroller = TextEditingController(); + TextEditingController addresstextcontroller = TextEditingController(); @override void initState() { super.initState(); - nametextcontroller = TextEditingController(); - addresstextcontroller = TextEditingController(); SchedulerBinding.instance.addPostFrameCallback((timeStamp) async { await cartPageBloc.getDatabaseValue(); }); @@ -59,25 +57,25 @@ class _CartPageContentState extends State { cartPageBloc = Provider.of(context); cartPageBloc.context = context; return Scaffold( - appBar: AppBar(elevation: 0.0,backgroundColor: Colors.transparent,), - body: SingleChildScrollView( - child: Container( - height: MediaQuery.of(context).size.height, - padding: EdgeInsets.only(left: 30.0,top: 30.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text("My Order",style: TextStyle(fontWeight: FontWeight.bold,color: Colors.black,fontSize: 35.0),), - Padding( - padding: const EdgeInsets.only(right:25.0), - child: Divider(thickness: 2.0,), - ), - createListCart(), - createTotalPriceWidget(), - ], - ), - ), + appBar: AppBar(elevation: 0.0,backgroundColor: Colors.transparent,), + body: SingleChildScrollView( + child: Container( + height: MediaQuery.of(context).size.height, + padding: EdgeInsets.only(left: 30.0,top: 30.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text("My Order",style: TextStyle(fontWeight: FontWeight.bold,color: Colors.black,fontSize: 35.0),), + Padding( + padding: const EdgeInsets.only(right:25.0), + child: Divider(thickness: 2.0,), ), + createListCart(), + createTotalPriceWidget(), + ], + ), + ), + ), ); } @@ -176,21 +174,17 @@ class _CartPageContentState extends State { child: ListBody( children: [ Text('Fill Details'), - new Expanded( - child: new TextField( - controller: nametextcontroller, - autofocus: true, - decoration: new InputDecoration( - labelText: 'Name', hintText: 'eg. Akshay'), - ), - ) , - new Expanded( - child: new TextField( - controller: addresstextcontroller, - autofocus: true, - decoration: new InputDecoration( - labelText: 'Address', hintText: 'eg. st road west chembur'), - ), + TextField( + controller: nametextcontroller, + autofocus: true, + decoration: InputDecoration( + labelText: 'Name', hintText: 'eg. Akshay'), + ), + TextField( + controller: addresstextcontroller, + autofocus: true, + decoration: InputDecoration( + labelText: 'Address', hintText: 'eg. st road west chembur'), ), ], ), @@ -220,54 +214,3 @@ class _CartPageContentState extends State { addresstextcontroller.dispose(); } } - -class CartItems extends StatefulWidget { - final Food fooddata; - CartItems(this.fooddata); - - @override - _CartItemsState createState() => _CartItemsState(); -} - -class _CartItemsState extends State { - @override - Widget build(BuildContext context) { - return GestureDetector( - child: Container( - color: UniversalVariables.whiteLightColor, - padding: EdgeInsets.symmetric(horizontal: 0.0,vertical: 10.0), - child:ListTile( - leading: Container(child: ClipRRect(borderRadius: BorderRadius.circular(5.0), - child: Image.network(widget.fooddata.image,fit: BoxFit.cover,)),height: 80.0,width: 80.0,), - title: Text(widget.fooddata.name,style: TextStyle(fontSize: 17.0,fontWeight: FontWeight.bold,color: Colors.black),), - subtitle: Text("${widget.fooddata.price}\$",style: TextStyle(fontWeight: FontWeight.bold,color: Colors.black54),), - trailing: IconButton(icon: Icon(Icons.delete,size: 20.0,), onPressed:()=>deleteFoodFromCart(widget.fooddata.keys) ,), - ) - ), - ); - } - - deleteFoodFromCart(String keys) async{ - DatabaseSql databaseSql=DatabaseSql(); - await databaseSql.openDatabaseSql(); - bool isDeleted = await databaseSql.deleteData(keys); - if(isDeleted){ - final snackBar= SnackBar( - content: Text('Removed Food Item'), - action: SnackBarAction( - label: 'Undo', - onPressed: () { - // todo code to undo the change. - }, - ), - ); - ScaffoldMessenger.of(context).showSnackBar(snackBar); - Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (BuildContext context) => CartPage())); - - } - } -} - diff --git a/lib/screens/FoodDetailPage.dart b/lib/screens/FoodDetailPage.dart index ef398c4..6ced8c7 100644 --- a/lib/screens/FoodDetailPage.dart +++ b/lib/screens/FoodDetailPage.dart @@ -49,7 +49,7 @@ class _FoodDetailPageContentState extends State { final GlobalKey _scaffoldKey = new GlobalKey(); // sample discription for food details - String sampleDescription="The existence of the Positioned forces the Container to the left, instead of centering. Removing the Positioned, however, puts the Container in the middle-center"; + String sampleDescription = "The existence of the Positioned forces the Container to the left, instead of centering. Removing the Positioned, however, puts the Container in the middle-center"; @override @@ -121,6 +121,7 @@ class _FoodDetailPageContentState extends State { ) ); } + createdetails(){ return Container( padding: EdgeInsets.all(10.0), diff --git a/lib/screens/MyOrderPage.dart b/lib/screens/MyOrderPage.dart index 58d7780..65e45ea 100644 --- a/lib/screens/MyOrderPage.dart +++ b/lib/screens/MyOrderPage.dart @@ -34,19 +34,13 @@ class _MyOrderPageState extends State { FirebaseHelper mFirebaseHelper = FirebaseHelper(); FirebaseUser currentUser; - getuser()async{ - - - } @override void initState() { - // TODO: implement initState super.initState(); - getuser(); SchedulerBinding.instance.addPostFrameCallback((timeStamp) async { currentUser= await authMethods.getCurrentUser(); mFirebaseHelper.fetchOrders(currentUser).then((List list){ - // there are not much sync operation in my order page, i.e didn;t made any bloc file :) + // there are not much sync operation in myorder page, i.e didn;t made any bloc file :) setState(() { requestList = list; }); diff --git a/lib/screens/homepage.dart b/lib/screens/homepage.dart index 52a8310..f04dc64 100644 --- a/lib/screens/homepage.dart +++ b/lib/screens/homepage.dart @@ -147,22 +147,22 @@ class _HomePageContentState extends State { ), )).toList(); - return Padding( - padding: const EdgeInsets.symmetric(vertical: 15.0), - child: Container( - child: Column(children: [ - CarouselSlider( - options: CarouselOptions( - autoPlay: true, - aspectRatio: 2.0, - enlargeCenterPage: true, - enlargeStrategy: CenterPageEnlargeStrategy.height, - ), - items: imageSliders, + return Padding( + padding: const EdgeInsets.symmetric(vertical: 15.0), + child: Container( + child: Column(children: [ + CarouselSlider( + options: CarouselOptions( + autoPlay: true, + aspectRatio: 2.0, + enlargeCenterPage: true, + enlargeStrategy: CenterPageEnlargeStrategy.height, ), - ],) - ), - ); + items: imageSliders, + ), + ],) + ), + ); } createDrawer(){ diff --git a/lib/widgets/cartitemswidget.dart b/lib/widgets/cartitemswidget.dart new file mode 100644 index 0000000..8c9e338 --- /dev/null +++ b/lib/widgets/cartitemswidget.dart @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2021 Akshay Jadhav + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import 'package:flutter/material.dart'; +import 'package:food_delivery_app/models/Food.dart'; +import 'package:food_delivery_app/resourese/databaseSQL.dart'; +import 'package:food_delivery_app/screens/CartPage.dart'; +import 'package:food_delivery_app/utils/universal_variables.dart'; + +class CartItems extends StatefulWidget { + final Food fooddata; + CartItems(this.fooddata); + + @override + _CartItemsState createState() => _CartItemsState(); +} + +class _CartItemsState extends State { + @override + Widget build(BuildContext context) { + return GestureDetector( + child: Container( + color: UniversalVariables.whiteLightColor, + padding: EdgeInsets.symmetric(horizontal: 0.0,vertical: 10.0), + child:ListTile( + leading: Container(child: ClipRRect(borderRadius: BorderRadius.circular(5.0), + child: Image.network(widget.fooddata.image,fit: BoxFit.cover,)),height: 80.0,width: 80.0,), + title: Text(widget.fooddata.name,style: TextStyle(fontSize: 17.0,fontWeight: FontWeight.bold,color: Colors.black),), + subtitle: Text("${widget.fooddata.price}\$",style: TextStyle(fontWeight: FontWeight.bold,color: Colors.black54),), + trailing: IconButton(icon: Icon(Icons.delete,size: 20.0,), onPressed:()=>deleteFoodFromCart(widget.fooddata.keys) ,), + ) + ), + ); + } + + deleteFoodFromCart(String keys) async{ + DatabaseSql databaseSql=DatabaseSql(); + await databaseSql.openDatabaseSql(); + bool isDeleted = await databaseSql.deleteData(keys); + if(isDeleted){ + final snackBar= SnackBar( + content: Text('Removed Food Item'), + action: SnackBarAction( + label: 'Undo', + onPressed: () { + // todo code to undo the change. + }, + ), + ); + ScaffoldMessenger.of(context).showSnackBar(snackBar); + Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (BuildContext context) => CartPage())); + } + } +} diff --git a/lib/widgets/foodTitleWidget.dart b/lib/widgets/foodTitleWidget.dart index 199a28c..118b3b7 100644 --- a/lib/widgets/foodTitleWidget.dart +++ b/lib/widgets/foodTitleWidget.dart @@ -21,7 +21,7 @@ class FoodTitleWidget extends StatelessWidget { pageBuilder: (_, __, ___) => FoodDetailPage(food:fooddata))); } return GestureDetector( - onTap: ()=>gotoFoodDetails(), + onTap: () => gotoFoodDetails(), child: Container( padding: EdgeInsets.symmetric(horizontal: 20.0,vertical: 10.0), child:Row( @@ -41,15 +41,7 @@ class FoodTitleWidget extends StatelessWidget { runSpacing: 4.0, // gap between lines direction: Axis.vertical, children: [ - Flexible( - child: RichText( - overflow: TextOverflow.ellipsis, - strutStyle: StrutStyle(fontSize: 20.0), - text: TextSpan( - style: TextStyle(fontSize: 16.0,color: Colors.black54,fontWeight: FontWeight.bold), - text: fooddata.name), - ), - ), + Text("${fooddata.name}\$", overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold,color: Colors.black54),), Row( children: [ SizedBox(height: 10.0,), diff --git a/pubspec.yaml b/pubspec.yaml index 3e70612..6cf1b08 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.0+1 +version: 2.0.0+1 environment: sdk: ">=2.7.0 <3.0.0"