From cc460ec8a097157a77419ab0fc83260b1f7197f0 Mon Sep 17 00:00:00 2001 From: Atharv Joshi Date: Wed, 10 Nov 2021 00:27:24 +0530 Subject: [PATCH 1/8] inverted visibility icons in login signup as they are logically correct , added color theme for icons, relevant variable names, back button to login page from signup page --- lib/views/auth/login_view.dart | 12 +++++----- lib/views/auth/signup_view.dart | 34 +++++++++++++++++++--------- lib/views/get_user_details_view.dart | 8 ++++--- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/lib/views/auth/login_view.dart b/lib/views/auth/login_view.dart index 7744be9..6607769 100644 --- a/lib/views/auth/login_view.dart +++ b/lib/views/auth/login_view.dart @@ -19,7 +19,7 @@ class LoginScreenState extends State { String? _email, _password; FocusNode? _emailFocusNode, _passwordFocusNode, _loginFocusNode; - bool _loading = false, _showPassword = true; + bool _loading = false, _isPasswordHidden = true; @override void initState() { @@ -124,19 +124,19 @@ class LoginScreenState extends State { child: TextFormField( focusNode: _passwordFocusNode, keyboardType: TextInputType.visiblePassword, - obscureText: _showPassword, + obscureText: _isPasswordHidden, enabled: true, textInputAction: TextInputAction.done, decoration: textFieldDecoration( hintText: 'Password', suffixIcon: IconButton( - icon: _showPassword - ? const Icon(Icons.visibility) - : const Icon(Icons.visibility_off), + icon: _isPasswordHidden + ? const Icon(Icons.visibility_off, color: RelicColors.backgroundColor,) + : const Icon(Icons.visibility, color: RelicColors.warningColor,), onPressed: () { setState( () { - _showPassword = !_showPassword; + _isPasswordHidden = !_isPasswordHidden; }, ); }, //for show and hide password diff --git a/lib/views/auth/signup_view.dart b/lib/views/auth/signup_view.dart index 2be8d3d..a95f60c 100644 --- a/lib/views/auth/signup_view.dart +++ b/lib/views/auth/signup_view.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart'; +import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/helpers/input_validators.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; import 'package:relic_bazaar/services/auth_service.dart'; @@ -16,7 +17,7 @@ class SignUpScreen extends StatefulWidget { class SignUpScreenState extends State { final GlobalKey _formKey = GlobalKey(); - bool showPassword = true, showConfirmPassword = true, _loading = false; + bool isPasswordHidden = true, isConfirmPasswordHidden = true, _loading = false; String? _email, _password, _confirmPassword; FocusNode? _emailFocusNode, _passwordFocusNode, @@ -127,18 +128,18 @@ class SignUpScreenState extends State { child: TextFormField( focusNode: _passwordFocusNode, keyboardType: TextInputType.visiblePassword, - obscureText: showPassword, + obscureText: isPasswordHidden, enabled: true, textInputAction: TextInputAction.next, decoration: textFieldDecoration( hintText: 'Password', suffixIcon: IconButton( - icon: showPassword - ? const Icon(Icons.visibility) - : const Icon(Icons.visibility_off), + icon: isPasswordHidden + ? const Icon(Icons.visibility_off, color: RelicColors.backgroundColor,) + : const Icon(Icons.visibility, color: RelicColors.warningColor,), onPressed: () { setState(() { - showPassword = !showPassword; + isPasswordHidden = !isPasswordHidden; }); }, //for show and hide password ), @@ -166,18 +167,18 @@ class SignUpScreenState extends State { child: TextFormField( focusNode: _confirmPasswordFocusNode, keyboardType: TextInputType.visiblePassword, - obscureText: showConfirmPassword, + obscureText: isConfirmPasswordHidden, enabled: true, textInputAction: TextInputAction.done, decoration: textFieldDecoration( hintText: 'Confirm Password', suffixIcon: IconButton( - icon: showConfirmPassword - ? const Icon(Icons.visibility) - : const Icon(Icons.visibility_off), + icon: isConfirmPasswordHidden + ? const Icon(Icons.visibility_off, color: RelicColors.backgroundColor,) + : const Icon(Icons.visibility, color: RelicColors.warningColor,), onPressed: () { setState(() { - showConfirmPassword = !showConfirmPassword; + isConfirmPasswordHidden = !isConfirmPasswordHidden; }); }, //for show and hide password ), @@ -270,6 +271,17 @@ class SignUpScreenState extends State { ), ), ), + Center( + child: TextButton( + onPressed: () => Navigator.pop(context), + child: const Text( + 'Login', + style: TextStyle( + color: Colors.white, + ), + ), + ), + ), ], ), ), diff --git a/lib/views/get_user_details_view.dart b/lib/views/get_user_details_view.dart index deecc53..a932db0 100644 --- a/lib/views/get_user_details_view.dart +++ b/lib/views/get_user_details_view.dart @@ -225,9 +225,11 @@ class _GetUserDetailsViewState extends State { context: context, ); } - setState(() { - _isLoading = false; - }); + if(mounted){ + setState(() { + _isLoading = false; + }); + } }); } } From 603b877c652be4eaa4927630ac9d23e4a01903fd Mon Sep 17 00:00:00 2001 From: Atharv Joshi Date: Wed, 10 Nov 2021 00:31:29 +0530 Subject: [PATCH 2/8] Revert "inverted visibility icons in login signup as they are logically correct , added color theme for icons, relevant variable names, back button to login page from signup page" This reverts commit cc460ec8a097157a77419ab0fc83260b1f7197f0. --- lib/views/auth/login_view.dart | 12 +++++----- lib/views/auth/signup_view.dart | 34 +++++++++------------------- lib/views/get_user_details_view.dart | 8 +++---- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/lib/views/auth/login_view.dart b/lib/views/auth/login_view.dart index 6607769..7744be9 100644 --- a/lib/views/auth/login_view.dart +++ b/lib/views/auth/login_view.dart @@ -19,7 +19,7 @@ class LoginScreenState extends State { String? _email, _password; FocusNode? _emailFocusNode, _passwordFocusNode, _loginFocusNode; - bool _loading = false, _isPasswordHidden = true; + bool _loading = false, _showPassword = true; @override void initState() { @@ -124,19 +124,19 @@ class LoginScreenState extends State { child: TextFormField( focusNode: _passwordFocusNode, keyboardType: TextInputType.visiblePassword, - obscureText: _isPasswordHidden, + obscureText: _showPassword, enabled: true, textInputAction: TextInputAction.done, decoration: textFieldDecoration( hintText: 'Password', suffixIcon: IconButton( - icon: _isPasswordHidden - ? const Icon(Icons.visibility_off, color: RelicColors.backgroundColor,) - : const Icon(Icons.visibility, color: RelicColors.warningColor,), + icon: _showPassword + ? const Icon(Icons.visibility) + : const Icon(Icons.visibility_off), onPressed: () { setState( () { - _isPasswordHidden = !_isPasswordHidden; + _showPassword = !_showPassword; }, ); }, //for show and hide password diff --git a/lib/views/auth/signup_view.dart b/lib/views/auth/signup_view.dart index a95f60c..2be8d3d 100644 --- a/lib/views/auth/signup_view.dart +++ b/lib/views/auth/signup_view.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart'; -import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/helpers/input_validators.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; import 'package:relic_bazaar/services/auth_service.dart'; @@ -17,7 +16,7 @@ class SignUpScreen extends StatefulWidget { class SignUpScreenState extends State { final GlobalKey _formKey = GlobalKey(); - bool isPasswordHidden = true, isConfirmPasswordHidden = true, _loading = false; + bool showPassword = true, showConfirmPassword = true, _loading = false; String? _email, _password, _confirmPassword; FocusNode? _emailFocusNode, _passwordFocusNode, @@ -128,18 +127,18 @@ class SignUpScreenState extends State { child: TextFormField( focusNode: _passwordFocusNode, keyboardType: TextInputType.visiblePassword, - obscureText: isPasswordHidden, + obscureText: showPassword, enabled: true, textInputAction: TextInputAction.next, decoration: textFieldDecoration( hintText: 'Password', suffixIcon: IconButton( - icon: isPasswordHidden - ? const Icon(Icons.visibility_off, color: RelicColors.backgroundColor,) - : const Icon(Icons.visibility, color: RelicColors.warningColor,), + icon: showPassword + ? const Icon(Icons.visibility) + : const Icon(Icons.visibility_off), onPressed: () { setState(() { - isPasswordHidden = !isPasswordHidden; + showPassword = !showPassword; }); }, //for show and hide password ), @@ -167,18 +166,18 @@ class SignUpScreenState extends State { child: TextFormField( focusNode: _confirmPasswordFocusNode, keyboardType: TextInputType.visiblePassword, - obscureText: isConfirmPasswordHidden, + obscureText: showConfirmPassword, enabled: true, textInputAction: TextInputAction.done, decoration: textFieldDecoration( hintText: 'Confirm Password', suffixIcon: IconButton( - icon: isConfirmPasswordHidden - ? const Icon(Icons.visibility_off, color: RelicColors.backgroundColor,) - : const Icon(Icons.visibility, color: RelicColors.warningColor,), + icon: showConfirmPassword + ? const Icon(Icons.visibility) + : const Icon(Icons.visibility_off), onPressed: () { setState(() { - isConfirmPasswordHidden = !isConfirmPasswordHidden; + showConfirmPassword = !showConfirmPassword; }); }, //for show and hide password ), @@ -271,17 +270,6 @@ class SignUpScreenState extends State { ), ), ), - Center( - child: TextButton( - onPressed: () => Navigator.pop(context), - child: const Text( - 'Login', - style: TextStyle( - color: Colors.white, - ), - ), - ), - ), ], ), ), diff --git a/lib/views/get_user_details_view.dart b/lib/views/get_user_details_view.dart index a932db0..deecc53 100644 --- a/lib/views/get_user_details_view.dart +++ b/lib/views/get_user_details_view.dart @@ -225,11 +225,9 @@ class _GetUserDetailsViewState extends State { context: context, ); } - if(mounted){ - setState(() { - _isLoading = false; - }); - } + setState(() { + _isLoading = false; + }); }); } } From 9a7d3baa5d525287f27f7a694bd5633aeec30679 Mon Sep 17 00:00:00 2001 From: Atharv Joshi Date: Sat, 20 Nov 2021 19:32:52 +0530 Subject: [PATCH 3/8] password visibilty icons reversed , login button on sigup page , fit type to cover password visibility icons reversed on login form and sign up form , app theme added to these icons link to go back to login page added on signup form BoxFit.cover added to user photo on get user details --- lib/views/auth/login_view.dart | 4 ++-- lib/views/auth/signup_view.dart | 21 +++++++++++++++++---- lib/views/get_user_details_view.dart | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/views/auth/login_view.dart b/lib/views/auth/login_view.dart index 7744be9..1e4976f 100644 --- a/lib/views/auth/login_view.dart +++ b/lib/views/auth/login_view.dart @@ -131,8 +131,8 @@ class LoginScreenState extends State { hintText: 'Password', suffixIcon: IconButton( icon: _showPassword - ? const Icon(Icons.visibility) - : const Icon(Icons.visibility_off), + ? const Icon(Icons.visibility_off , color: RelicColors.backgroundColor,) + : const Icon(Icons.visibility , color: RelicColors.warningColor,), onPressed: () { setState( () { diff --git a/lib/views/auth/signup_view.dart b/lib/views/auth/signup_view.dart index 2be8d3d..11fa76f 100644 --- a/lib/views/auth/signup_view.dart +++ b/lib/views/auth/signup_view.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart'; +import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/helpers/input_validators.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; import 'package:relic_bazaar/services/auth_service.dart'; @@ -134,8 +135,8 @@ class SignUpScreenState extends State { hintText: 'Password', suffixIcon: IconButton( icon: showPassword - ? const Icon(Icons.visibility) - : const Icon(Icons.visibility_off), + ? const Icon(Icons.visibility_off , color: RelicColors.backgroundColor,) + : const Icon(Icons.visibility , color: RelicColors.warningColor,), onPressed: () { setState(() { showPassword = !showPassword; @@ -173,8 +174,8 @@ class SignUpScreenState extends State { hintText: 'Confirm Password', suffixIcon: IconButton( icon: showConfirmPassword - ? const Icon(Icons.visibility) - : const Icon(Icons.visibility_off), + ? const Icon(Icons.visibility_off , color: RelicColors.backgroundColor,) + : const Icon(Icons.visibility , color: RelicColors.warningColor,), onPressed: () { setState(() { showConfirmPassword = !showConfirmPassword; @@ -267,6 +268,18 @@ class SignUpScreenState extends State { 'assets/items/google.png', ), ), + + ), + ), + ), + Center( + child: TextButton( + onPressed: () => Navigator.pop(context), + child: const Text( + 'Login', + style: TextStyle( + color: Colors.white, + ), ), ), ), diff --git a/lib/views/get_user_details_view.dart b/lib/views/get_user_details_view.dart index deecc53..be13101 100644 --- a/lib/views/get_user_details_view.dart +++ b/lib/views/get_user_details_view.dart @@ -120,7 +120,7 @@ class _GetUserDetailsViewState extends State { Icons.add_a_photo, size: 40, ) - : Image.file(_image!), + : Image.file(_image! , fit: BoxFit.cover,), ), ), SizedBox( From 9a2c93ca5ef61ffcdfc225606b0eca34ece8090e Mon Sep 17 00:00:00 2001 From: Atharv Joshi Date: Mon, 22 Nov 2021 16:20:50 +0530 Subject: [PATCH 4/8] cart system , delete button configured --- lib/helpers/cart_total_controller.dart | 9 + lib/model/product_model.dart | 15 +- lib/services/product_service.dart | 13 ++ lib/views/cart_view.dart | 214 ++++++++++++++---------- lib/widgets/payment/cart_item.dart | 191 ++++++++++++--------- lib/widgets/payment/payment_window.dart | 39 +++-- lib/widgets/product/product_card.dart | 2 +- lib/widgets/product/product_page.dart | 90 ++++++---- pubspec.yaml | 2 + test/widget_test.dart | 6 +- 10 files changed, 355 insertions(+), 226 deletions(-) create mode 100644 lib/helpers/cart_total_controller.dart diff --git a/lib/helpers/cart_total_controller.dart b/lib/helpers/cart_total_controller.dart new file mode 100644 index 0000000..ec294d7 --- /dev/null +++ b/lib/helpers/cart_total_controller.dart @@ -0,0 +1,9 @@ +import 'package:get/get.dart'; + +class CartTotalController extends GetxController{ + RxInt cartTotal = 0.obs; + + updateCartTotal(int newValue ){ + cartTotal += newValue; + } +} \ No newline at end of file diff --git a/lib/model/product_model.dart b/lib/model/product_model.dart index ac214eb..ca581b7 100644 --- a/lib/model/product_model.dart +++ b/lib/model/product_model.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + class Product { Product({ this.text, @@ -6,11 +8,16 @@ class Product { this.image, this.seller, this.height, + this.id, + this.dbId }); - factory Product.fromJson(dynamic productData) { + factory Product.fromJson(Map productData) { + // log('prodcut id : ${productData['_id'].runtimeType}'); return Product( - amount: productData['amount'].toString(), + amount: productData['amount'], + id : productData['id'], + dbId: productData['_id'], image: productData['image'].toString() == '' ? 'assets/items/${productData['id']}.png' : productData['image'].toString(), @@ -25,8 +32,10 @@ class Product { final String? text; final String? owner; - final String? amount; + final int? amount; final String? image; final String? seller; final int? height; + final int? id; + final String? dbId; } diff --git a/lib/services/product_service.dart b/lib/services/product_service.dart index ee82230..77ceacb 100644 --- a/lib/services/product_service.dart +++ b/lib/services/product_service.dart @@ -1,4 +1,6 @@ import 'dart:convert'; +import 'dart:developer'; +import 'package:flutter/cupertino.dart'; import 'package:http/http.dart' as http; import 'package:relic_bazaar/model/product_model.dart'; @@ -15,4 +17,15 @@ class ProductService { ) .toList(); } + + Future getProductDetails(String index) async { + print('index : $index'); + final http.Response response = await http.get( + Uri.parse('https://himanshusharma89-api.herokuapp.com/relic_bazaar/products/$index'), + ); + final Product product = Product.fromJson(json.decode(response.body)); + print(product.text); + return product; + } + } diff --git a/lib/views/cart_view.dart b/lib/views/cart_view.dart index 542b4c6..2d70402 100644 --- a/lib/views/cart_view.dart +++ b/lib/views/cart_view.dart @@ -1,8 +1,13 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:relic_bazaar/helpers/cart_total_controller.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/widgets/payment/cart_item.dart'; import 'package:relic_bazaar/widgets/payment/payment_window.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; +import 'package:shared_preferences/shared_preferences.dart'; class Cart extends StatefulWidget { const Cart({ @@ -17,109 +22,136 @@ class Cart extends StatefulWidget { } class _CartState extends State { + CartTotalController _cartTotalController = Get.put(CartTotalController()); + @override + void initState() { + // TODO: implement initState + // getMyCart(); + } + + Future> getMyCart() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + return prefs.getStringList('myCart') ?? []; + } + @override Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; final double width = MediaQuery.of(context).size.width; - return Padding( - padding: const EdgeInsets.symmetric( - horizontal: 12, - ), - child: ListView( - children: [ - SizedBox( - height: height * 0.01, - ), - const Text( - 'Your Cart', - style: TextStyle( - fontSize: 30, - color: Colors.white, - fontWeight: FontWeight.w700, + return FutureBuilder>( + future: getMyCart(), + builder: (_ , AsyncSnapshot> snapShot){ + if(snapShot.hasData){ + List myCart = snapShot.data ?? []; + return Padding( + padding: const EdgeInsets.symmetric( + horizontal: 12, ), - textAlign: TextAlign.left, - ), - SizedBox( - height: height * 0.01, - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - GestureDetector( - onTap: () { - setState(() { - widget.pageController!.jumpTo(0); - }); - }, - child: RelicBazaarStackedView( - upperColor: Colors.white, - height: height * 0.045, - width: width * 0.4, - borderColor: Colors.white, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: const [ - Icon( - Icons.arrow_back, - size: 20, + child: ListView( + children: [ + SizedBox( + height: height * 0.01, + ), + const Text( + 'Your Cart', + style: TextStyle( + fontSize: 30, + color: Colors.white, + fontWeight: FontWeight.w700, + ), + textAlign: TextAlign.left, + ), + SizedBox( + height: height * 0.01, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + GestureDetector( + onTap: () { + setState(() { + widget.pageController!.jumpTo(0); + }); + }, + child: RelicBazaarStackedView( + upperColor: Colors.white, + height: height * 0.045, + width: width * 0.4, + borderColor: Colors.white, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + Icon( + Icons.arrow_back, + size: 20, + ), + Text( + ' back to shop', + style: TextStyle( + fontFamily: 'pix M 8pt', + fontSize: 15, + fontWeight: FontWeight.bold, + color: RelicColors.primaryBlack, + ), + ), + ], + ), ), - Text( - ' back to shop', - style: TextStyle( - fontFamily: 'pix M 8pt', - fontSize: 15, - fontWeight: FontWeight.bold, - color: RelicColors.primaryBlack, + ), + RelicBazaarStackedView( + upperColor: Colors.black, + lowerColor: Colors.white, + height: height * 0.045, + width: width * 0.22, + child: Center( + child: Text( + // '${ myCart.length.toString()} items', + myCart.length.toString(), + style: const TextStyle( + fontFamily: 'pix M 8pt', + fontSize: 15, + color: Colors.white, + ), + textAlign: TextAlign.center, ), ), - ], - ), + ), + ], ), - ), - RelicBazaarStackedView( - upperColor: Colors.black, - lowerColor: Colors.white, - height: height * 0.045, - width: width * 0.22, - child: const Center( - child: Text( - '5 items', - style: TextStyle( - fontFamily: 'pix M 8pt', - fontSize: 15, - color: Colors.white, + const Divider( + color: Colors.white, + thickness: 0.9, + ), + Column( + children: [ + ListView.builder( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemCount: myCart.length, + itemBuilder: (BuildContext context, int index) { + return CartItem(index : myCart[index], pageController: widget.pageController,); + }, ), - textAlign: TextAlign.center, - ), + Align( + alignment: Alignment.bottomCenter, + child: PaymentWindow(), + ), + SizedBox( + height: height * 0.08, + ), + ], ), - ), - ], - ), - const Divider( - color: Colors.white, - thickness: 0.9, - ), - Column( - children: [ - ListView.builder( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - itemCount: 5, - itemBuilder: (BuildContext context, int index) { - return CartItem(); - }, - ), - Align( - alignment: Alignment.bottomCenter, - child: PaymentWindow(), - ), - SizedBox( - height: height * 0.08, - ), - ], + ], + ), + ); + } + return const Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation(Colors.white), ), - ], - ), + ); + + } ); } } diff --git a/lib/widgets/payment/cart_item.dart b/lib/widgets/payment/cart_item.dart index 0cb352c..50aabdd 100644 --- a/lib/widgets/payment/cart_item.dart +++ b/lib/widgets/payment/cart_item.dart @@ -1,14 +1,24 @@ import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:relic_bazaar/helpers/cart_total_controller.dart'; +import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/model/product_model.dart'; +import 'package:relic_bazaar/services/product_service.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; +import 'package:shared_preferences/shared_preferences.dart'; class CartItem extends StatefulWidget { + CartItem({required this.index, this.pageController}); + final String index; + final PageController? pageController; @override _CartItemState createState() => _CartItemState(); } class _CartItemState extends State { TextEditingController? controller; - + Product? product; + CartTotalController _cartTotalController = Get.find(); @override void initState() { super.initState(); @@ -20,87 +30,118 @@ class _CartItemState extends State { Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; final double width = MediaQuery.of(context).size.width; - return Padding( - padding: const EdgeInsets.only(bottom: 10.0), - child: Row( - children: [ - RelicBazaarStackedView( - height: width * 0.3, - width: width * 0.3, - upperColor: Colors.white, - ), - Expanded( - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 12), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - 'Product Name', - style: TextStyle( - fontSize: 21, - fontWeight: FontWeight.bold, - color: Colors.white), - ), - const Text( - 'Name', - style: TextStyle(color: Colors.white), - ), - SizedBox( - height: height * 0.005, - ), - Container( - // width: 75, - // height: 25, - height: height * 0.04, - width: width * 0.25, - decoration: const BoxDecoration( - color: Colors.white, - boxShadow: [ - BoxShadow( - offset: Offset(0, 4), - blurRadius: 8, - color: Colors.black26) - ]), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, + return FutureBuilder( + future: ProductService().getProductDetails(widget.index), + builder: (_ , AsyncSnapshot snapShot){ + if(snapShot.hasData){ + Product product = snapShot.data!; + _cartTotalController.updateCartTotal(product.amount ?? 0); + return Padding( + padding: const EdgeInsets.only(bottom: 10.0), + child: Row( + children: [ + RelicBazaarStackedView( + height: width * 0.3, + width: width * 0.3, + upperColor: Colors.white, + child: Image.asset(product.image!), + ), + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 12), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - GestureDetector( - onTap: addQuantity, - child: const Icon(Icons.add), - ), - Expanded( - child: TextField( - textAlign: TextAlign.center, + Text( + product.text ?? 'Product Name', style: const TextStyle( - fontSize: 17, - fontWeight: FontWeight.bold, - ), - readOnly: true, - controller: controller, - decoration: const InputDecoration( - border: InputBorder.none, - isDense: true, - contentPadding: EdgeInsets.all(0)), - )), - GestureDetector( - onTap: subQuantity, - child: const Icon(Icons.remove), + fontSize: 21, + fontWeight: FontWeight.bold, + color: Colors.white), ), + Text( + product.owner ?? 'Product owner', + style: const TextStyle(color: Colors.white), + ), + SizedBox( + height: height * 0.005, + ), + Container( + // width: 75, + // height: 25, + height: height * 0.04, + width: width * 0.25, + decoration: const BoxDecoration( + color: Colors.white, + boxShadow: [ + BoxShadow( + offset: Offset(0, 4), + blurRadius: 8, + color: Colors.black26) + ]), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + GestureDetector( + onTap: addQuantity, + child: const Icon(Icons.add), + ), + Expanded( + child: TextField( + textAlign: TextAlign.center, + style: const TextStyle( + fontSize: 17, + fontWeight: FontWeight.bold, + ), + readOnly: true, + controller: controller, + decoration: const InputDecoration( + border: InputBorder.none, + isDense: true, + contentPadding: EdgeInsets.all(0)), + )), + GestureDetector( + onTap: subQuantity, + child: const Icon(Icons.remove), + ), + ], + ), + ) ], ), - ) - ], - ), + ), + ), + Column( + children: [ + IconButton( + onPressed: () async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + List myCart = prefs.getStringList('myCart') ?? []; + myCart.remove(widget.index); + prefs.setStringList('myCart', myCart); + widget.pageController!.jumpToPage(1); + widget.pageController!.jumpToPage(2); + }, + icon: const Icon(Icons.delete) , color: RelicColors.warningColor,), + Text( + '₹ ${product.amount}', + style: const TextStyle( + fontWeight: FontWeight.bold, color: Colors.white, fontSize: 17), + ) + ], + ), + + ], ), + ); + } + return const Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation(Colors.white), ), - const Text( - '₹65654', - style: TextStyle( - fontWeight: FontWeight.bold, color: Colors.white, fontSize: 17), - ) - ], - ), + ); + }, + ); } diff --git a/lib/widgets/payment/payment_window.dart b/lib/widgets/payment/payment_window.dart index 40a3930..64b6ffb 100644 --- a/lib/widgets/payment/payment_window.dart +++ b/lib/widgets/payment/payment_window.dart @@ -1,8 +1,10 @@ import 'package:flutter/material.dart'; +import 'package:relic_bazaar/helpers/cart_total_controller.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; import 'package:razorpay_flutter/razorpay_flutter.dart'; import 'package:fluttertoast/fluttertoast.dart'; +import 'package:get/get.dart'; class PaymentWindow extends StatefulWidget { @override @@ -12,6 +14,7 @@ class PaymentWindow extends StatefulWidget { class _PaymentWindowState extends State { int? cnt1, cnt2; final Razorpay _razorpay = Razorpay(); + CartTotalController _cartTotalController = Get.find(); @override void initState() { super.initState(); @@ -78,19 +81,23 @@ class _PaymentWindowState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: const [ - Text( - 'CART TOTAL', - style: TextStyle(fontSize: 17), - ), - Text( - '₹35465', - style: TextStyle(fontSize: 17), + // Obx( + // () => + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Text( + 'CART TOTAL', + style: TextStyle(fontSize: 17), + ), + Text( + _cartTotalController.cartTotal.toString() ?? '', + style: const TextStyle(fontSize: 17), + ), + ], ), - ], - ), + // ), + SizedBox( height: height * 0.002, ), @@ -296,14 +303,14 @@ class _PaymentWindowState extends State { ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: const [ - Text( + children: [ + const Text( 'TOTAL', style: TextStyle(fontSize: 17), ), Text( - '₹35131', - style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold), + _cartTotalController.cartTotal.toString() ?? '', + style: const TextStyle(fontSize: 25, fontWeight: FontWeight.bold), ), ], ), diff --git a/lib/widgets/product/product_card.dart b/lib/widgets/product/product_card.dart index 28530ae..0d50319 100644 --- a/lib/widgets/product/product_card.dart +++ b/lib/widgets/product/product_card.dart @@ -59,7 +59,7 @@ class ProductCard extends StatelessWidget { height: 20, ), Text( - product!.amount!, + product!.amount!.toString(), style: const TextStyle( fontSize: 18, color: Colors.white, diff --git a/lib/widgets/product/product_page.dart b/lib/widgets/product/product_page.dart index 450d4e5..485b507 100644 --- a/lib/widgets/product/product_page.dart +++ b/lib/widgets/product/product_page.dart @@ -5,6 +5,7 @@ import 'package:relic_bazaar/helpers/ad_state.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/model/product_model.dart'; import 'package:relic_bazaar/widgets/back_button.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import '../../helpers/app_icons.dart'; import '../retro_button.dart'; @@ -19,7 +20,6 @@ class ProductPage extends StatefulWidget { class _ProductPageState extends State { BannerAd? bannerAd; - @override void didChangeDependencies() { final AdState adState = Provider.of(context); @@ -46,19 +46,24 @@ class _ProductPageState extends State { elevation: 0.0, backgroundColor: Colors.transparent, leading: appBarBackButton(context), - actions: const [ - Center( - child: RelicBazaarStackedView( - upperColor: Colors.white, - width: 35, - height: 35, - borderColor: Colors.white, - child: Padding( - padding: EdgeInsets.only(top: 7, left: 6), - child: Icon( - RelicIcons.cart, - size: 32, - color: Colors.black, + actions: [ + InkWell( + onTap: (){ + Navigator.pop(context); + }, + child: const Center( + child: RelicBazaarStackedView( + upperColor: Colors.white, + width: 35, + height: 35, + borderColor: Colors.white, + child: Padding( + padding: EdgeInsets.only(top: 7, left: 6), + child: Icon( + RelicIcons.cart, + size: 32, + color: Colors.black, + ), ), ), ), @@ -187,7 +192,7 @@ class _ProductPageState extends State { borderColor: Colors.white, child: Center( child: Text( - widget.product!.amount!, + widget.product!.amount!.toString(), style: const TextStyle( fontWeight: FontWeight.bold, color: RelicColors.primaryColor, @@ -273,28 +278,39 @@ class _ProductPageState extends State { SizedBox( width: width * 0.02, ), - RelicBazaarStackedView( - upperColor: Colors.white, - width: width * 0.35, - height: height * 0.05, - borderColor: Colors.white, - child: Row( - mainAxisAlignment: - MainAxisAlignment.spaceAround, - children: const [ - Icon( - Icons.add, - color: RelicColors.primaryColor, - ), - Text( - 'ADD TO CART', - style: TextStyle( - color: RelicColors - .primaryColor, - fontWeight: FontWeight.bold, - fontSize: 15), - ), - ], + InkWell( + onTapDown: (_){ + + }, + onTap: () async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + List myCart = prefs.getStringList('myCart') ?? []; + myCart.add(widget.product!.id!.toString() ); + prefs.setStringList('myCart', myCart); + }, + child: RelicBazaarStackedView( + upperColor: Colors.white, + width: width * 0.35, + height: height * 0.05, + borderColor: Colors.white, + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceAround, + children: const [ + Icon( + Icons.add, + color: RelicColors.primaryColor, + ), + Text( + 'ADD TO CART', + style: TextStyle( + color: RelicColors + .primaryColor, + fontWeight: FontWeight.bold, + fontSize: 15), + ), + ], + ), ), ) ], diff --git a/pubspec.yaml b/pubspec.yaml index fb815fa..19195ce 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -34,6 +34,8 @@ dependencies: image_picker: any firebase_storage: ^10.0.3 intl: ^0.17.0 + shared_preferences: + get: ^4.3.8 dev_dependencies: flutter_test: diff --git a/test/widget_test.dart b/test/widget_test.dart index f1c5215..a85b81c 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -30,7 +30,7 @@ void main() { product: Product( text: 'lorem', owner: 'ipsum', - amount: 'dolor', + amount: 0, image: 'assets/items/3.png', seller: 'seller', height: 10, @@ -64,7 +64,7 @@ void main() { child: ProductPage( product: Product( owner: 'owner', - amount: 'amount', + amount: 0, seller: 'seller', height: 10, text: 'test string', @@ -136,7 +136,7 @@ void main() { textDirection: TextDirection.ltr, child: Scaffold( body: MaterialApp( - home: CartItem(), + home: CartItem(index: '1',), ), ), ), From c51e61b06c58ac84d63aff2ea3db07c49983ee47 Mon Sep 17 00:00:00 2001 From: Atharv Joshi Date: Mon, 22 Nov 2021 16:49:34 +0530 Subject: [PATCH 5/8] item amount updates depending on the selected quantity --- lib/widgets/payment/cart_item.dart | 17 ++++++++++++++--- lib/widgets/payment/payment_window.dart | 4 ++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/widgets/payment/cart_item.dart b/lib/widgets/payment/cart_item.dart index 50aabdd..b46730f 100644 --- a/lib/widgets/payment/cart_item.dart +++ b/lib/widgets/payment/cart_item.dart @@ -18,6 +18,8 @@ class CartItem extends StatefulWidget { class _CartItemState extends State { TextEditingController? controller; Product? product; + int quantity = 1; + int itemTotal = 0; CartTotalController _cartTotalController = Get.find(); @override void initState() { @@ -36,6 +38,7 @@ class _CartItemState extends State { if(snapShot.hasData){ Product product = snapShot.data!; _cartTotalController.updateCartTotal(product.amount ?? 0); + itemTotal = product.amount! * quantity; return Padding( padding: const EdgeInsets.only(bottom: 10.0), child: Row( @@ -124,7 +127,7 @@ class _CartItemState extends State { }, icon: const Icon(Icons.delete) , color: RelicColors.warningColor,), Text( - '₹ ${product.amount}', + '₹ $itemTotal', style: const TextStyle( fontWeight: FontWeight.bold, color: Colors.white, fontSize: 17), ) @@ -147,13 +150,21 @@ class _CartItemState extends State { void subQuantity() { if (int.parse(controller!.text) > 1) { - controller!.text = (int.parse(controller!.text) - 1).toString(); + controller!.text = (int.parse(controller!.text) - 1).toString(); + setState(() { + quantity = int.parse(controller!.text); + print('quantity : $quantity'); + }); } } void addQuantity() { if (int.parse(controller!.text) < 50) { - controller!.text = (int.parse(controller!.text) + 1).toString(); + controller!.text = (int.parse(controller!.text) + 1).toString(); + setState(() { + quantity = int.parse(controller!.text); + print('quantity : $quantity'); + }); } } } diff --git a/lib/widgets/payment/payment_window.dart b/lib/widgets/payment/payment_window.dart index 64b6ffb..6b7eb3b 100644 --- a/lib/widgets/payment/payment_window.dart +++ b/lib/widgets/payment/payment_window.dart @@ -91,7 +91,7 @@ class _PaymentWindowState extends State { style: TextStyle(fontSize: 17), ), Text( - _cartTotalController.cartTotal.toString() ?? '', + _cartTotalController.cartTotal.toString(), style: const TextStyle(fontSize: 17), ), ], @@ -309,7 +309,7 @@ class _PaymentWindowState extends State { style: TextStyle(fontSize: 17), ), Text( - _cartTotalController.cartTotal.toString() ?? '', + _cartTotalController.cartTotal.toString(), style: const TextStyle(fontSize: 25, fontWeight: FontWeight.bold), ), ], From 21fee40dcc202e606dbf3e08a525cf8f8bb2f5c4 Mon Sep 17 00:00:00 2001 From: Atharv Joshi Date: Mon, 22 Nov 2021 20:01:35 +0530 Subject: [PATCH 6/8] added shimmer effect in cart list --- lib/widgets/payment/cart_item.dart | 276 ++++++++++++++++++----------- pubspec.yaml | 1 + 2 files changed, 174 insertions(+), 103 deletions(-) diff --git a/lib/widgets/payment/cart_item.dart b/lib/widgets/payment/cart_item.dart index b46730f..7779ea8 100644 --- a/lib/widgets/payment/cart_item.dart +++ b/lib/widgets/payment/cart_item.dart @@ -6,6 +6,7 @@ import 'package:relic_bazaar/model/product_model.dart'; import 'package:relic_bazaar/services/product_service.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:shimmer/shimmer.dart'; class CartItem extends StatefulWidget { CartItem({required this.index, this.pageController}); @@ -32,119 +33,188 @@ class _CartItemState extends State { Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; final double width = MediaQuery.of(context).size.width; - return FutureBuilder( - future: ProductService().getProductDetails(widget.index), - builder: (_ , AsyncSnapshot snapShot){ - if(snapShot.hasData){ - Product product = snapShot.data!; - _cartTotalController.updateCartTotal(product.amount ?? 0); - itemTotal = product.amount! * quantity; - return Padding( - padding: const EdgeInsets.only(bottom: 10.0), - child: Row( - children: [ - RelicBazaarStackedView( - height: width * 0.3, - width: width * 0.3, - upperColor: Colors.white, - child: Image.asset(product.image!), - ), - Expanded( - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 12), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - product.text ?? 'Product Name', - style: const TextStyle( - fontSize: 21, - fontWeight: FontWeight.bold, - color: Colors.white), - ), - Text( - product.owner ?? 'Product owner', - style: const TextStyle(color: Colors.white), - ), - SizedBox( - height: height * 0.005, - ), - Container( - // width: 75, - // height: 25, - height: height * 0.04, - width: width * 0.25, - decoration: const BoxDecoration( - color: Colors.white, - boxShadow: [ - BoxShadow( - offset: Offset(0, 4), - blurRadius: 8, - color: Colors.black26) - ]), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - GestureDetector( - onTap: addQuantity, - child: const Icon(Icons.add), - ), - Expanded( - child: TextField( - textAlign: TextAlign.center, - style: const TextStyle( - fontSize: 17, - fontWeight: FontWeight.bold, - ), - readOnly: true, - controller: controller, - decoration: const InputDecoration( - border: InputBorder.none, - isDense: true, - contentPadding: EdgeInsets.all(0)), - )), - GestureDetector( - onTap: subQuantity, - child: const Icon(Icons.remove), - ), - ], + return Container( + margin: EdgeInsets.symmetric(vertical: 5), + child: FutureBuilder( + future: ProductService().getProductDetails(widget.index), + builder: (_ , AsyncSnapshot snapShot){ + if(snapShot.hasData){ + Product product = snapShot.data!; + _cartTotalController.updateCartTotal(product.amount ?? 0); + itemTotal = product.amount! * quantity; + return Padding( + padding: const EdgeInsets.only(bottom: 10.0), + child: Row( + children: [ + RelicBazaarStackedView( + height: width * 0.3, + width: width * 0.3, + upperColor: Colors.white, + child: Image.asset(product.image!), + ), + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 12), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + product.text ?? 'Product Name', + style: const TextStyle( + fontSize: 21, + fontWeight: FontWeight.bold, + color: Colors.white), ), - ) - ], + Text( + product.owner ?? 'Product owner', + style: const TextStyle(color: Colors.white), + ), + SizedBox( + height: height * 0.005, + ), + Container( + // width: 75, + // height: 25, + height: height * 0.04, + width: width * 0.25, + decoration: const BoxDecoration( + color: Colors.white, + boxShadow: [ + BoxShadow( + offset: Offset(0, 4), + blurRadius: 8, + color: Colors.black26) + ]), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + GestureDetector( + onTap: addQuantity, + child: const Icon(Icons.add), + ), + Expanded( + child: TextField( + textAlign: TextAlign.center, + style: const TextStyle( + fontSize: 17, + fontWeight: FontWeight.bold, + ), + readOnly: true, + controller: controller, + decoration: const InputDecoration( + border: InputBorder.none, + isDense: true, + contentPadding: EdgeInsets.all(0)), + )), + GestureDetector( + onTap: subQuantity, + child: const Icon(Icons.remove), + ), + ], + ), + ) + ], + ), ), ), + Column( + children: [ + IconButton( + onPressed: () async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + List myCart = prefs.getStringList('myCart') ?? []; + myCart.remove(widget.index); + prefs.setStringList('myCart', myCart); + widget.pageController!.jumpToPage(0); + // widget.pageController!.jumpToPage(2); + }, + icon: const Icon(Icons.delete) , color: RelicColors.warningColor,), + Text( + '₹ $itemTotal', + style: const TextStyle( + fontWeight: FontWeight.bold, color: Colors.white, fontSize: 17), + ) + ], + ), + + ], + ), + ); + } + return Container( + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: 120.0, + height: 120.0, + child: Shimmer.fromColors( + baseColor: Colors.grey[300]!, + highlightColor: Colors.grey[100]!, + child: Container( + // width: 200.0, + // height: 100.0, + color: Colors.grey, + ), + ), + ), + const SizedBox( + width: 20, ), Column( children: [ - IconButton( - onPressed: () async { - SharedPreferences prefs = await SharedPreferences.getInstance(); - List myCart = prefs.getStringList('myCart') ?? []; - myCart.remove(widget.index); - prefs.setStringList('myCart', myCart); - widget.pageController!.jumpToPage(1); - widget.pageController!.jumpToPage(2); - }, - icon: const Icon(Icons.delete) , color: RelicColors.warningColor,), - Text( - '₹ $itemTotal', - style: const TextStyle( - fontWeight: FontWeight.bold, color: Colors.white, fontSize: 17), - ) + Container( + margin: EdgeInsets.symmetric(vertical: 5), + width: MediaQuery.of(context).size.width * 0.5, + height: 20.0, + child: Shimmer.fromColors( + baseColor: Colors.grey[300]!, + highlightColor: Colors.grey[100]!, + child: Container( + // width: 200.0, + // height: 100.0, + color: Colors.grey, + ), + ), + ), + Container( + margin: EdgeInsets.only(bottom: 5), + width: MediaQuery.of(context).size.width * 0.5, + height: 20.0, + child: Shimmer.fromColors( + baseColor: Colors.grey[300]!, + highlightColor: Colors.grey[100]!, + child: Container( + // width: 200.0, + // height: 100.0, + color: Colors.grey, + ), + ), + ), + Container( + margin: EdgeInsets.only(bottom: 5), + width: MediaQuery.of(context).size.width * 0.5, + height: 20.0, + child: Shimmer.fromColors( + baseColor: Colors.grey[300]!, + highlightColor: Colors.grey[100]!, + child: Container( + // width: 200.0, + // height: 100.0, + color: Colors.grey, + ), + ), + ), ], ), - ], ), - ); - } - return const Center( - child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation(Colors.white), - ), - ); - }, + );; + }, + + ), ); } @@ -167,4 +237,4 @@ class _CartItemState extends State { }); } } -} +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 19195ce..57e9a4c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -36,6 +36,7 @@ dependencies: intl: ^0.17.0 shared_preferences: get: ^4.3.8 + shimmer: ^2.0.0 dev_dependencies: flutter_test: From 017865e6b06148fb011b5c6f795f94292de7d5ce Mon Sep 17 00:00:00 2001 From: Atharv Joshi Date: Mon, 22 Nov 2021 20:23:14 +0530 Subject: [PATCH 7/8] hardcoded payment values , added const to constructors --- lib/widgets/payment/cart_item.dart | 7 ++++--- lib/widgets/payment/payment_window.dart | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/widgets/payment/cart_item.dart b/lib/widgets/payment/cart_item.dart index 7779ea8..45d667f 100644 --- a/lib/widgets/payment/cart_item.dart +++ b/lib/widgets/payment/cart_item.dart @@ -118,6 +118,7 @@ class _CartItemState extends State { ), ), Column( + mainAxisAlignment: MainAxisAlignment.end, children: [ IconButton( onPressed: () async { @@ -165,7 +166,7 @@ class _CartItemState extends State { Column( children: [ Container( - margin: EdgeInsets.symmetric(vertical: 5), + margin: const EdgeInsets.symmetric(vertical: 5), width: MediaQuery.of(context).size.width * 0.5, height: 20.0, child: Shimmer.fromColors( @@ -179,7 +180,7 @@ class _CartItemState extends State { ), ), Container( - margin: EdgeInsets.only(bottom: 5), + margin: const EdgeInsets.only(bottom: 5), width: MediaQuery.of(context).size.width * 0.5, height: 20.0, child: Shimmer.fromColors( @@ -193,7 +194,7 @@ class _CartItemState extends State { ), ), Container( - margin: EdgeInsets.only(bottom: 5), + margin: const EdgeInsets.only(bottom: 5), width: MediaQuery.of(context).size.width * 0.5, height: 20.0, child: Shimmer.fromColors( diff --git a/lib/widgets/payment/payment_window.dart b/lib/widgets/payment/payment_window.dart index 6b7eb3b..1ec4efd 100644 --- a/lib/widgets/payment/payment_window.dart +++ b/lib/widgets/payment/payment_window.dart @@ -90,8 +90,8 @@ class _PaymentWindowState extends State { 'CART TOTAL', style: TextStyle(fontSize: 17), ), - Text( - _cartTotalController.cartTotal.toString(), + const Text( + '1000', style: const TextStyle(fontSize: 17), ), ], @@ -308,8 +308,8 @@ class _PaymentWindowState extends State { 'TOTAL', style: TextStyle(fontSize: 17), ), - Text( - _cartTotalController.cartTotal.toString(), + const Text( + '1000', style: const TextStyle(fontSize: 25, fontWeight: FontWeight.bold), ), ], From 2e84a6d3a73fd7d22949fe303a2e71ec2be0f307 Mon Sep 17 00:00:00 2001 From: Atharv Joshi Date: Wed, 24 Nov 2021 09:03:42 +0530 Subject: [PATCH 8/8] removed unused imports , files , added type annotations --- lib/helpers/cart_total_controller.dart | 9 ------- lib/model/product_model.dart | 3 +-- lib/services/product_service.dart | 2 -- lib/views/cart_view.dart | 15 ++--------- lib/widgets/payment/cart_item.dart | 30 ++++++--------------- lib/widgets/payment/payment_window.dart | 36 +++++++++++-------------- lib/widgets/product/product_page.dart | 6 ++--- pubspec.yaml | 1 - 8 files changed, 29 insertions(+), 73 deletions(-) delete mode 100644 lib/helpers/cart_total_controller.dart diff --git a/lib/helpers/cart_total_controller.dart b/lib/helpers/cart_total_controller.dart deleted file mode 100644 index ec294d7..0000000 --- a/lib/helpers/cart_total_controller.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:get/get.dart'; - -class CartTotalController extends GetxController{ - RxInt cartTotal = 0.obs; - - updateCartTotal(int newValue ){ - cartTotal += newValue; - } -} \ No newline at end of file diff --git a/lib/model/product_model.dart b/lib/model/product_model.dart index ca581b7..554bd69 100644 --- a/lib/model/product_model.dart +++ b/lib/model/product_model.dart @@ -1,4 +1,3 @@ -import 'dart:developer'; class Product { Product({ @@ -12,7 +11,7 @@ class Product { this.dbId }); - factory Product.fromJson(Map productData) { + factory Product.fromJson(Map productData) { // log('prodcut id : ${productData['_id'].runtimeType}'); return Product( amount: productData['amount'], diff --git a/lib/services/product_service.dart b/lib/services/product_service.dart index 77ceacb..6d4c2a5 100644 --- a/lib/services/product_service.dart +++ b/lib/services/product_service.dart @@ -1,6 +1,4 @@ import 'dart:convert'; -import 'dart:developer'; -import 'package:flutter/cupertino.dart'; import 'package:http/http.dart' as http; import 'package:relic_bazaar/model/product_model.dart'; diff --git a/lib/views/cart_view.dart b/lib/views/cart_view.dart index 2d70402..8dec52f 100644 --- a/lib/views/cart_view.dart +++ b/lib/views/cart_view.dart @@ -1,8 +1,4 @@ -import 'dart:developer'; - import 'package:flutter/material.dart'; -import 'package:get/get.dart'; -import 'package:relic_bazaar/helpers/cart_total_controller.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/widgets/payment/cart_item.dart'; import 'package:relic_bazaar/widgets/payment/payment_window.dart'; @@ -22,16 +18,10 @@ class Cart extends StatefulWidget { } class _CartState extends State { - CartTotalController _cartTotalController = Get.put(CartTotalController()); - @override - void initState() { - // TODO: implement initState - // getMyCart(); - } Future> getMyCart() async { SharedPreferences prefs = await SharedPreferences.getInstance(); - return prefs.getStringList('myCart') ?? []; + return prefs.getStringList('myCart') ?? []; } @override @@ -42,7 +32,7 @@ class _CartState extends State { future: getMyCart(), builder: (_ , AsyncSnapshot> snapShot){ if(snapShot.hasData){ - List myCart = snapShot.data ?? []; + List myCart = snapShot.data ?? []; return Padding( padding: const EdgeInsets.symmetric( horizontal: 12, @@ -105,7 +95,6 @@ class _CartState extends State { width: width * 0.22, child: Center( child: Text( - // '${ myCart.length.toString()} items', myCart.length.toString(), style: const TextStyle( fontFamily: 'pix M 8pt', diff --git a/lib/widgets/payment/cart_item.dart b/lib/widgets/payment/cart_item.dart index 45d667f..628738e 100644 --- a/lib/widgets/payment/cart_item.dart +++ b/lib/widgets/payment/cart_item.dart @@ -1,6 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:get/get.dart'; -import 'package:relic_bazaar/helpers/cart_total_controller.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/model/product_model.dart'; import 'package:relic_bazaar/services/product_service.dart'; @@ -21,7 +19,6 @@ class _CartItemState extends State { Product? product; int quantity = 1; int itemTotal = 0; - CartTotalController _cartTotalController = Get.find(); @override void initState() { super.initState(); @@ -34,13 +31,12 @@ class _CartItemState extends State { final double height = MediaQuery.of(context).size.height; final double width = MediaQuery.of(context).size.width; return Container( - margin: EdgeInsets.symmetric(vertical: 5), + margin: const EdgeInsets.symmetric(vertical: 5), child: FutureBuilder( future: ProductService().getProductDetails(widget.index), builder: (_ , AsyncSnapshot snapShot){ if(snapShot.hasData){ Product product = snapShot.data!; - _cartTotalController.updateCartTotal(product.amount ?? 0); itemTotal = product.amount! * quantity; return Padding( padding: const EdgeInsets.only(bottom: 10.0), @@ -73,8 +69,6 @@ class _CartItemState extends State { height: height * 0.005, ), Container( - // width: 75, - // height: 25, height: height * 0.04, width: width * 0.25, decoration: const BoxDecoration( @@ -84,7 +78,8 @@ class _CartItemState extends State { offset: Offset(0, 4), blurRadius: 8, color: Colors.black26) - ]), + ] + ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ @@ -119,15 +114,14 @@ class _CartItemState extends State { ), Column( mainAxisAlignment: MainAxisAlignment.end, - children: [ + children: [ IconButton( onPressed: () async { SharedPreferences prefs = await SharedPreferences.getInstance(); - List myCart = prefs.getStringList('myCart') ?? []; + List myCart = prefs.getStringList('myCart') ?? []; myCart.remove(widget.index); prefs.setStringList('myCart', myCart); widget.pageController!.jumpToPage(0); - // widget.pageController!.jumpToPage(2); }, icon: const Icon(Icons.delete) , color: RelicColors.warningColor,), Text( @@ -146,7 +140,7 @@ class _CartItemState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, - children: [ + children: [ SizedBox( width: 120.0, height: 120.0, @@ -154,8 +148,6 @@ class _CartItemState extends State { baseColor: Colors.grey[300]!, highlightColor: Colors.grey[100]!, child: Container( - // width: 200.0, - // height: 100.0, color: Colors.grey, ), ), @@ -164,7 +156,7 @@ class _CartItemState extends State { width: 20, ), Column( - children: [ + children: [ Container( margin: const EdgeInsets.symmetric(vertical: 5), width: MediaQuery.of(context).size.width * 0.5, @@ -173,8 +165,6 @@ class _CartItemState extends State { baseColor: Colors.grey[300]!, highlightColor: Colors.grey[100]!, child: Container( - // width: 200.0, - // height: 100.0, color: Colors.grey, ), ), @@ -187,8 +177,6 @@ class _CartItemState extends State { baseColor: Colors.grey[300]!, highlightColor: Colors.grey[100]!, child: Container( - // width: 200.0, - // height: 100.0, color: Colors.grey, ), ), @@ -201,8 +189,6 @@ class _CartItemState extends State { baseColor: Colors.grey[300]!, highlightColor: Colors.grey[100]!, child: Container( - // width: 200.0, - // height: 100.0, color: Colors.grey, ), ), @@ -211,7 +197,7 @@ class _CartItemState extends State { ), ], ), - );; + ); }, diff --git a/lib/widgets/payment/payment_window.dart b/lib/widgets/payment/payment_window.dart index 1ec4efd..4e8ed53 100644 --- a/lib/widgets/payment/payment_window.dart +++ b/lib/widgets/payment/payment_window.dart @@ -1,10 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:relic_bazaar/helpers/cart_total_controller.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; import 'package:razorpay_flutter/razorpay_flutter.dart'; import 'package:fluttertoast/fluttertoast.dart'; -import 'package:get/get.dart'; class PaymentWindow extends StatefulWidget { @override @@ -14,7 +12,6 @@ class PaymentWindow extends StatefulWidget { class _PaymentWindowState extends State { int? cnt1, cnt2; final Razorpay _razorpay = Razorpay(); - CartTotalController _cartTotalController = Get.find(); @override void initState() { super.initState(); @@ -81,22 +78,19 @@ class _PaymentWindowState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - // Obx( - // () => - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Text( - 'CART TOTAL', - style: TextStyle(fontSize: 17), - ), - const Text( - '1000', - style: const TextStyle(fontSize: 17), - ), - ], + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Text( + 'CART TOTAL', + style: TextStyle(fontSize: 17), + ), + const Text( + '1000', + style: const TextStyle(fontSize: 17), ), - // ), + ], + ), SizedBox( height: height * 0.002, @@ -117,7 +111,7 @@ class _PaymentWindowState extends State { ), Padding( padding: - const EdgeInsets.symmetric(horizontal: 10, vertical: 2), + const EdgeInsets.symmetric(horizontal: 10, vertical: 2), child: Column( children: [ SizedBox( @@ -174,7 +168,7 @@ class _PaymentWindowState extends State { padding: const EdgeInsets.all(4.0), child: Row( mainAxisAlignment: - MainAxisAlignment.spaceBetween, + MainAxisAlignment.spaceBetween, children: [ FittedBox( child: Text( @@ -263,7 +257,7 @@ class _PaymentWindowState extends State { padding: const EdgeInsets.all(4.0), child: Row( mainAxisAlignment: - MainAxisAlignment.spaceBetween, + MainAxisAlignment.spaceBetween, children: [ FittedBox( child: Text( diff --git a/lib/widgets/product/product_page.dart b/lib/widgets/product/product_page.dart index 485b507..f7cdd48 100644 --- a/lib/widgets/product/product_page.dart +++ b/lib/widgets/product/product_page.dart @@ -68,7 +68,7 @@ class _ProductPageState extends State { ), ), ), - SizedBox( + const SizedBox( width: 10, ) ], @@ -284,8 +284,8 @@ class _ProductPageState extends State { }, onTap: () async { SharedPreferences prefs = await SharedPreferences.getInstance(); - List myCart = prefs.getStringList('myCart') ?? []; - myCart.add(widget.product!.id!.toString() ); + List myCart = prefs.getStringList('myCart') ?? []; + myCart.add(widget.product!.id!.toString()); prefs.setStringList('myCart', myCart); }, child: RelicBazaarStackedView( diff --git a/pubspec.yaml b/pubspec.yaml index 57e9a4c..51cf1dc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,7 +35,6 @@ dependencies: firebase_storage: ^10.0.3 intl: ^0.17.0 shared_preferences: - get: ^4.3.8 shimmer: ^2.0.0 dev_dependencies: