From 0170505376bdc7a15f2d0e4ba0f1a8bf66ebeb9f Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Tue, 4 Jun 2024 23:13:21 +0300 Subject: [PATCH] Fix: category colors and count elements --- android/app/build.gradle | 2 +- lib/pages/basket.dart | 15 +++++++++------ lib/pages/detail.dart | 16 +++++++++++----- lib/pages/main.dart | 9 +++------ 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index d9b7933..da742a0 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -46,7 +46,7 @@ android { // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdkVersion 21 - targetSdkVersion flutter.targetSdkVersion + targetSdkVersion 34 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } diff --git a/lib/pages/basket.dart b/lib/pages/basket.dart index 14c37a5..2e0f528 100644 --- a/lib/pages/basket.dart +++ b/lib/pages/basket.dart @@ -109,13 +109,16 @@ class _BasketPageState extends State { } void addItem(String id) async { + final item = + cartItems.firstWhere((element) => element.id == id, orElse: () { + final cartItem = gymCart.firstWhere((element) => element.id == id); + cartItem.localCount = 0; + return cartItem; + }); + if (item.localCount + 1 > item.count) { + return; + } setState(() { - final item = - cartItems.firstWhere((element) => element.id == id, orElse: () { - final cartItem = gymCart.firstWhere((element) => element.id == id); - cartItem.localCount = 0; - return cartItem; - }); item.localCount++; cartItems[cartItems.indexOf(item)].localCount = item.localCount; totalPrice = diff --git a/lib/pages/detail.dart b/lib/pages/detail.dart index 27c4b2b..da824c7 100644 --- a/lib/pages/detail.dart +++ b/lib/pages/detail.dart @@ -269,13 +269,19 @@ class _DetailPageState extends State { item!.images[0].url, height: 400, ), - Padding( + Center( + child: Padding( padding: const EdgeInsets.symmetric(vertical: 10), - child: Center( - child: Text(categoryName != null - ? 'Категория: ${categoryName == "" ? "Без категории" : categoryName}' + child: Chip( + label: Text(categoryName != null + ? (categoryName == "" + ? "Без категории" + : categoryName!) : ''), - )), + backgroundColor: Colors.white, + ), + ), + ), Center( child: MarkdownBody( data: '### Отстаток: _${item!.count}_', diff --git a/lib/pages/main.dart b/lib/pages/main.dart index caca34c..e5b9438 100644 --- a/lib/pages/main.dart +++ b/lib/pages/main.dart @@ -8,7 +8,6 @@ import 'package:gymlink_module_web/pages/basket.dart'; import 'package:gymlink_module_web/pages/detail.dart'; import 'package:gymlink_module_web/pages/order_history.dart'; import 'package:gymlink_module_web/providers/cart.dart'; -import 'package:gymlink_module_web/providers/main.dart'; import 'package:gymlink_module_web/tools/items.dart'; import 'package:gymlink_module_web/tools/prefs.dart'; import 'package:gymlink_module_web/tools/relative.dart'; @@ -148,6 +147,8 @@ class _MainPageState extends State { _onSearch(); } }), + textInputAction: TextInputAction.search, + onSubmitted: (_) => _onSearch(), decoration: InputDecoration( hintText: 'Поиск', border: OutlineInputBorder( @@ -231,12 +232,8 @@ class _MainPageState extends State { horizontal: 10, vertical: 10), child: Chip( label: Text(category.name), - //FIXME: проблема с цветом backgroundColor: selectedCategory == category - ? context - .read() - .theme - .primaryColorLight + ? Theme.of(context).primaryColor : Colors.white, labelStyle: TextStyle( color: selectedCategory == category