Skip to content

Commit

Permalink
cleaned and extracted cartItemsWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshay0701 committed Jul 31, 2021
1 parent c4a6813 commit 07d8607
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 137 deletions.
5 changes: 3 additions & 2 deletions lib/blocs/FoodDetailPageBloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class FoodDetailPageBloc with ChangeNotifier {

List<Food> 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";

Expand Down
2 changes: 0 additions & 2 deletions lib/blocs/RegisterPageBloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions lib/resourese/firebase_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FirebaseHelper{
List<Food>foodList = <Food>[];

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){
Expand Down Expand Up @@ -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);
}
Expand Down
121 changes: 32 additions & 89 deletions lib/screens/CartPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -42,13 +41,12 @@ class CartPageContent extends StatefulWidget {
class _CartPageContentState extends State<CartPageContent> {

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();
});
Expand All @@ -59,25 +57,25 @@ class _CartPageContentState extends State<CartPageContent> {
cartPageBloc = Provider.of<CartPageBloc>(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(),
],
),
),
),
);
}

Expand Down Expand Up @@ -176,21 +174,17 @@ class _CartPageContentState extends State<CartPageContent> {
child: ListBody(
children: <Widget>[
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'),
),
],
),
Expand Down Expand Up @@ -220,54 +214,3 @@ class _CartPageContentState extends State<CartPageContent> {
addresstextcontroller.dispose();
}
}

class CartItems extends StatefulWidget {
final Food fooddata;
CartItems(this.fooddata);

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

class _CartItemsState extends State<CartItems> {
@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()));

}
}
}

3 changes: 2 additions & 1 deletion lib/screens/FoodDetailPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class _FoodDetailPageContentState extends State<FoodDetailPageContent> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

// 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
Expand Down Expand Up @@ -121,6 +121,7 @@ class _FoodDetailPageContentState extends State<FoodDetailPageContent> {
)
);
}

createdetails(){
return Container(
padding: EdgeInsets.all(10.0),
Expand Down
8 changes: 1 addition & 7 deletions lib/screens/MyOrderPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,13 @@ class _MyOrderPageState extends State<MyOrderPage> {
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<Request> 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;
});
Expand Down
30 changes: 15 additions & 15 deletions lib/screens/homepage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,22 @@ class _HomePageContentState extends State<HomePageContent> {
),
)).toList();

return Padding(
padding: const EdgeInsets.symmetric(vertical: 15.0),
child: Container(
child: Column(children: <Widget>[
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: <Widget>[
CarouselSlider(
options: CarouselOptions(
autoPlay: true,
aspectRatio: 2.0,
enlargeCenterPage: true,
enlargeStrategy: CenterPageEnlargeStrategy.height,
),
],)
),
);
items: imageSliders,
),
],)
),
);
}

createDrawer(){
Expand Down
70 changes: 70 additions & 0 deletions lib/widgets/cartitemswidget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2021 Akshay Jadhav <jadhavakshay0701@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/

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<CartItems> {
@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()));
}
}
}
12 changes: 2 additions & 10 deletions lib/widgets/foodTitleWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 07d8607

Please sign in to comment.