From 429ff2aff843da1d79d2a3125459948650c99e8d Mon Sep 17 00:00:00 2001 From: ManavSarkar Date: Sun, 19 Dec 2021 13:50:05 +0530 Subject: [PATCH 1/2] Removed the pubspec.lock file --- lib/Screens/product_details.dart | 605 ++++++++++++++++++++----------- 1 file changed, 387 insertions(+), 218 deletions(-) diff --git a/lib/Screens/product_details.dart b/lib/Screens/product_details.dart index 3220f42..f074625 100644 --- a/lib/Screens/product_details.dart +++ b/lib/Screens/product_details.dart @@ -10,6 +10,7 @@ import 'package:test_app/provider/user.dart'; import 'package:uuid/uuid.dart'; import 'package:test_app/services/order.dart'; +import 'package:test_app/model/cart_item.dart'; class ProductDetails extends StatefulWidget { final ProductModel product; @@ -36,261 +37,429 @@ class _ProductDetailsState extends State { final appProvider = Provider.of(context); return SafeArea( - child: Scaffold( - key: _key, - appBar: AppBar( - elevation: 0, + child: Scaffold( + key: _key, + appBar: AppBar( + elevation: 0, + backgroundColor: Colors.pink[50], + iconTheme: IconThemeData(color: Colors.black), + title: Text( + widget.product.name, + style: TextStyle( + color: Colors.black, + ), + ), + ), backgroundColor: Colors.pink[50], - iconTheme: IconThemeData(color: Colors.black), - ), - backgroundColor: Colors.pink[50], - body: ListView(physics: ScrollPhysics(), children: [ - Container( - height: 300, - child: GridTile( - child: Container( - color: Colors.white, - child: Carousel( - boxFit: BoxFit.cover, - images: [ - Image.network( - widget.product.pictures[0], - fit: BoxFit.fill, + body: ListView( + physics: ScrollPhysics(), + children: [ + Container( + height: 300, + child: Stack( + children: [ + GridTile( + child: Container( + color: Colors.white, + child: Carousel( + boxFit: BoxFit.cover, + images: [ + Image.network( + widget.product.pictures[0], + fit: BoxFit.fill, + ), + Image.network( + widget.product.pictures[1], + fit: BoxFit.fill, + ), + Image.network(widget.product.pictures[2]), + ], + animationCurve: Curves.fastOutSlowIn, + dotSize: 4.0, + indicatorBgPadding: 4.0, + ), ), - Image.network( - widget.product.pictures[1], - fit: BoxFit.fill, + footer: Container( + color: Colors.white70, + child: ListTile( + title: Center( + child: Text('' + //widget.product.name + ), + ), + ), ), - Image.network(widget.product.pictures[2]), - ], - animationCurve: Curves.fastOutSlowIn, - dotSize: 4.0, - indicatorBgPadding: 4.0, - )), - footer: Container( - color: Colors.white70, - child: ListTile( - title: Center( - child: Text('' - //widget.product.name + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: Align( + alignment: Alignment.topRight, + child: ClipOval( + child: Container( + decoration: BoxDecoration( + color: Colors.white, + ), + child: IconButton( + tooltip: "Add to Favourites", + icon: Icon( + Icons.favorite_rounded, + size: 28.0, + ), + onPressed: () async { + appProvider.changeIsLoading(); + bool success = await userProvider.addToFav( + product: widget.product); + if (success) { + _key.currentState.showSnackBar( + SnackBar(content: Text("Added to Fav!"))); + userProvider.reloadUserModel(); + appProvider.changeIsLoading(); + return; + } else { + _key.currentState.showSnackBar(SnackBar( + content: Text("Not added to Fav!"))); + appProvider.changeIsLoading(); + return; + } + appProvider.changeIsLoading(); + }, + color: Colors.red, + ), + ), ), - ), + ), + ), + ], ), ), - ), - ), - Row( - children: [ - Expanded( - child: DropdownButton( - value: size, - style: TextStyle(color: Colors.white), - items: widget.product.sizes - .map>( - (value) => DropdownMenuItem( - value: value, - child: Text(value, - style: TextStyle( - color: Colors.red, - )))) - .toList(), - onChanged: (value) { - setState(() { - size = value; - }); - }), - ), - Expanded(child: prodPrice()), - ], - ), - Row(children: [ - TextButton( - onPressed: () { - double pricef = prodPriceM(); - showDialog( - context: context, - builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(20.0)), - //this right here - child: Container( - height: 200, - child: Padding( - padding: const EdgeInsets.all(12.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'You will be charged $pricef upon delivery!', - textAlign: TextAlign.center, - ), - SizedBox( - width: 320.0, - child: ElevatedButton( - onPressed: () async { - var uuid = Uuid(); - String id = uuid.v4(); - if (userProvider.userModel.address != - '' && - userProvider.userModel.number != '') { - _orderServices.createOrder( - userId: userProvider.user.uid, - id: id, - description: widget.product.name, - status: "ordered", - totalPrice: pricef, - cart: userProvider.userModel.cart); - _key.currentState.showSnackBar(SnackBar( - content: Text("Order created!"))); - Navigator.pop(context); - } else { - _key.currentState.showSnackBar(SnackBar( - content: Text( - 'Please add address and number'))); - } - }, - child: Text( - "Accept", - style: TextStyle(color: Colors.white), - ), - style: ElevatedButton.styleFrom( - primary: const Color(0xFF1BC0C5), + Row( + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: Expanded( + child: ProdPrice(), + ), + ), + Expanded( + child: Align( + alignment: Alignment.centerRight, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: DropdownButton( + enableFeedback: true, + icon: Icon(Icons.timelapse), + value: size, + style: TextStyle( + color: Colors.white, + fontSize: 24.0, + ), + items: widget.product.sizes + .map>( + (value) => DropdownMenuItem( + value: value, + child: Text( + value, + style: TextStyle( + color: Colors.red, ), ), ), - SizedBox( - width: 320.0, - child: ElevatedButton( - onPressed: () { - Navigator.pop(context); - }, - child: Text( - "Reject", - style: TextStyle(color: Colors.white), - ), - style: ElevatedButton.styleFrom( - primary: Colors.red), - ), - ) //} - ], - ), - ), - ), - ); - }); - }, - child: Text( - 'Check Out', - style: TextStyle(color: Colors.red, fontSize: 18), - )), - appProvider.isLoading - ? Loading() - : IconButton( - icon: Icon(Icons.add_shopping_cart_rounded), - onPressed: () async { - appProvider.changeIsLoading(); - bool success = await userProvider.addToCart( - product: widget.product, size: size); - if (success) { - _key.currentState.showSnackBar( - SnackBar(content: Text("Added to Cart!"))); - userProvider.reloadUserModel(); - appProvider.changeIsLoading(); - return; - } else { - _key.currentState.showSnackBar( - SnackBar(content: Text("Not added to Cart!"))); - appProvider.changeIsLoading(); - return; - } - // appProvider.changeIsLoading(); - }, - color: Colors.red, + ) + .toList(), + onChanged: (value) { + setState(() { + size = value; + }); + }), + ), + ), ), - IconButton( - icon: Icon(Icons.favorite_rounded), - onPressed: () async { - appProvider.changeIsLoading(); - bool success = - await userProvider.addToFav(product: widget.product); - if (success) { - _key.currentState - .showSnackBar(SnackBar(content: Text("Added to Fav!"))); - userProvider.reloadUserModel(); - appProvider.changeIsLoading(); - return; - } else { - _key.currentState - .showSnackBar(SnackBar(content: Text("Not added to Fav!"))); - appProvider.changeIsLoading(); - return; - } - }, - color: Colors.red, - ), - ]), - Divider(), - Column( - children: [ + ], + ), Row( - mainAxisAlignment: MainAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Center( - child: Text( - 'Description', - style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + ElevatedButton( + style: ElevatedButton.styleFrom(primary: Colors.red), + child: Row( + children: [ + Icon( + Icons.shopping_bag_rounded, + color: Colors.white, + ), + VerticalDivider( + color: Colors.white, + thickness: 10.0, + ), + Text( + 'Check Out', + style: TextStyle(color: Colors.white, fontSize: 18), + ), + ], ), - ) + onPressed: () { + double pricef = ProdPriceM(); + showDialog( + context: context, + builder: (BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20.0)), + //this right here + child: Container( + height: 200, + child: Padding( + padding: const EdgeInsets.all(12.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'You will be charged ${pricef} upon delivery!', + textAlign: TextAlign.center, + ), + SizedBox( + width: 320.0, + child: RaisedButton( + onPressed: () async { + var uuid = Uuid(); + String id = uuid.v4(); + if (userProvider.userModel.address != + '' && + userProvider.userModel.number != + '') { + _orderServices.createOrder( + userId: userProvider.user.uid, + id: id, + description: + widget.product.name, + status: "ordered", + totalPrice: pricef, + cart: userProvider + .userModel.cart); + _key.currentState.showSnackBar( + SnackBar( + content: Text( + "Order created!"))); + Navigator.pop(context); + } else { + _key.currentState.showSnackBar(SnackBar( + content: Text( + 'Please add address and number'))); + } + }, + child: Text( + "Accept", + style: TextStyle(color: Colors.white), + ), + color: const Color(0xFF1BC0C5), + ), + ), + SizedBox( + width: 320.0, + child: RaisedButton( + onPressed: () { + Navigator.pop(context); + }, + child: Text( + "Reject", + style: + TextStyle(color: Colors.white), + ), + color: Colors.red), + ) //} + ], + ), + ), + ), + ); + }); + }, + ), + // RaisedButton( + // onPressed: () async { + // var uuid = Uuid(); + // String id = uuid.v4(); + // if (userProvider.userModel.address != '' && + // userProvider.userModel.number != '') { + // _orderServices.createOrder( + // userId: userProvider.user.uid, + // id: id, + // description: widget.product.name, + // status: "ordered", + // totalPrice: 0, + // cart: userProvider.userModel.cart); + // // for (CartItemModel cartItem in userProvider.userModel.cart) { + // // bool value = + // // await userProvider.removeFromCart(cartItem: cartItem); + // // if (value) { + // // userProvider.reloadUserModel(); + // // print("Item added to cart"); + // // _key.currentState.showSnackBar( + // // SnackBar(content: Text("Removed from Cart!"))); + // // } else { + // // print("ITEM WAS NOT REMOVED"); + // // } + // // } + // _key.currentState + // .showSnackBar(SnackBar(content: Text("Order created!"))); + // Navigator.pop(context); + // } else { + // _key.currentState.showSnackBar( + // SnackBar(content: Text('Please add address and number'))); + // } + // }, + // child: Text( + // "Accept", + // style: TextStyle(color: Colors.white), + // ), + // color: const Color(0xFF1BC0C5), + // ), + // SizedBox( + // width: 320.0, + // child: RaisedButton( + // onPressed: () { + // Navigator.pop(context); + // }, + // child: Text( + // "Reject", + // style: TextStyle(color: Colors.white), + // ), + // color: Colors.red), + // ), + appProvider.isLoading + ? Loading() + : ElevatedButton( + child: Row( + children: [ + Icon( + Icons.add_shopping_cart_rounded, + color: Colors.white, + ), + VerticalDivider( + color: Colors.white, + thickness: 10.0, + ), + Text( + 'Add to Cart', + style: + TextStyle(color: Colors.white, fontSize: 18), + ), + ], + ), + style: ElevatedButton.styleFrom(primary: Colors.orange), + onPressed: () async { + appProvider.changeIsLoading(); + bool success = await userProvider.addToCart( + product: widget.product, size: size); + if (success) { + _key.currentState.showSnackBar( + SnackBar(content: Text("Added to Cart!"))); + userProvider.reloadUserModel(); + appProvider.changeIsLoading(); + return; + } else { + _key.currentState.showSnackBar( + SnackBar(content: Text("Not added to Cart!"))); + appProvider.changeIsLoading(); + return; + } + appProvider.changeIsLoading(); + }, + ), ], ), - Divider(), - Text(widget.product.description), - Divider(), - Text('Why you should read?', - style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), - Divider(), - Text(widget.product.whyToRead), - Divider(), - Text( - 'Similar Books', - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 18, - ), + Divider( + thickness: 2.0, ), - Divider(), + Column( + children: [ + detailsTile( + "Description", + [ + Align( + alignment: Alignment.centerLeft, + child: Text( + widget.product.description, + ), + ), + ], + ), + Divider( + thickness: 2.0, + ), + detailsTile( + 'Why you should read?', + [ + Align( + alignment: Alignment.centerLeft, + child: Text(widget.product.whyToRead), + ), + ], + ), + Divider( + thickness: 2.0, + ), + detailsTile( + 'Similar Books', + [ + /*Container( + height: 360, + child: SimilarProducts(), + )*/ + ], + ), + ], + ) ], - ) - ]), - )); + ), + ), + ); + } + + Widget detailsTile(String title, List children) { + return ExpansionTile( + backgroundColor: Colors.pink[100], + tilePadding: EdgeInsets.all(4.0), + textColor: Colors.black, + title: Text( + title, + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + childrenPadding: EdgeInsets.symmetric(horizontal: 16), + children: children, + ); } - prodPrice() { + ProdPrice() { + TextStyle productPriceTextStyle = + TextStyle(color: Colors.black, fontSize: 24); switch (size) { case '1 week': return Text( 'Price: ${widget.product.prices[0]}', - style: TextStyle(color: Colors.black, fontSize: 18), + style: productPriceTextStyle, ); break; case '2 weeks': return Text( 'Price: ${widget.product.prices[1]}', - style: TextStyle(color: Colors.black, fontSize: 18), + style: productPriceTextStyle, ); break; case '3 weeks': return Text( 'Price: ${widget.product.prices[2]}', - style: TextStyle(color: Colors.black, fontSize: 18), + style: productPriceTextStyle, ); break; case '4 weeks': return Text( 'Price: ${widget.product.prices[3]}', - style: TextStyle(color: Colors.black, fontSize: 18), + style: productPriceTextStyle, ); break; default: @@ -298,7 +467,7 @@ class _ProductDetailsState extends State { } } - prodPriceM() { + ProdPriceM() { switch (size) { case '1 week': return widget.product.prices[0]; From 0098bab833b6f5e3b6fa7af73195fe389309463d Mon Sep 17 00:00:00 2001 From: ManavSarkar Date: Sun, 19 Dec 2021 14:01:48 +0530 Subject: [PATCH 2/2] fixed lint errors --- lib/Screens/product_details.dart | 41 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/Screens/product_details.dart b/lib/Screens/product_details.dart index f074625..20da941 100644 --- a/lib/Screens/product_details.dart +++ b/lib/Screens/product_details.dart @@ -10,7 +10,6 @@ import 'package:test_app/provider/user.dart'; import 'package:uuid/uuid.dart'; import 'package:test_app/services/order.dart'; -import 'package:test_app/model/cart_item.dart'; class ProductDetails extends StatefulWidget { final ProductModel product; @@ -121,7 +120,6 @@ class _ProductDetailsState extends State { appProvider.changeIsLoading(); return; } - appProvider.changeIsLoading(); }, color: Colors.red, ), @@ -137,7 +135,7 @@ class _ProductDetailsState extends State { Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0), child: Expanded( - child: ProdPrice(), + child: prodPrice(), ), ), Expanded( @@ -198,7 +196,7 @@ class _ProductDetailsState extends State { ], ), onPressed: () { - double pricef = ProdPriceM(); + double pricef = prodPriceM(); showDialog( context: context, builder: (BuildContext context) { @@ -215,12 +213,12 @@ class _ProductDetailsState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - 'You will be charged ${pricef} upon delivery!', + 'You will be charged $pricef upon delivery!', textAlign: TextAlign.center, ), SizedBox( width: 320.0, - child: RaisedButton( + child: ElevatedButton( onPressed: () async { var uuid = Uuid(); String id = uuid.v4(); @@ -252,21 +250,25 @@ class _ProductDetailsState extends State { "Accept", style: TextStyle(color: Colors.white), ), - color: const Color(0xFF1BC0C5), + style: ElevatedButton.styleFrom( + primary: const Color(0xFF1BC0C5), + ), ), ), SizedBox( width: 320.0, - child: RaisedButton( - onPressed: () { - Navigator.pop(context); - }, - child: Text( - "Reject", - style: - TextStyle(color: Colors.white), - ), - color: Colors.red), + child: ElevatedButton( + onPressed: () { + Navigator.pop(context); + }, + child: Text( + "Reject", + style: TextStyle(color: Colors.white), + ), + style: ElevatedButton.styleFrom( + primary: Colors.red, + ), + ), ) //} ], ), @@ -364,7 +366,6 @@ class _ProductDetailsState extends State { appProvider.changeIsLoading(); return; } - appProvider.changeIsLoading(); }, ), ], @@ -434,7 +435,7 @@ class _ProductDetailsState extends State { ); } - ProdPrice() { + Widget prodPrice() { TextStyle productPriceTextStyle = TextStyle(color: Colors.black, fontSize: 24); switch (size) { @@ -467,7 +468,7 @@ class _ProductDetailsState extends State { } } - ProdPriceM() { + prodPriceM() { switch (size) { case '1 week': return widget.product.prices[0];