From 9902666c0cccbe70997a302903969a4957177e84 Mon Sep 17 00:00:00 2001 From: mohamadmahdi jebeli Date: Wed, 16 Jul 2025 13:39:31 +0330 Subject: [PATCH] update category --- .../customize_category_state.dart | 15 +++++-- .../customize_category/favorites_step.dart | 39 ++++++++++++------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/lib/views/customize_category/customize_category_state.dart b/lib/views/customize_category/customize_category_state.dart index b48578a..d02142b 100644 --- a/lib/views/customize_category/customize_category_state.dart +++ b/lib/views/customize_category/customize_category_state.dart @@ -24,6 +24,7 @@ class CustomizeCategoryState extends CoreProvier { Future getFavourites() async { appState = AppState.busy; + update(); final service = RequestService( RequestHelper.favourites(), @@ -31,13 +32,19 @@ class CustomizeCategoryState extends CoreProvier { await service.httpGet(); if (service.isSuccess) { faves.clear(); - final favourites = service.data('types'); - for (var i = 0; i < favourites.length; i++) { - faves.add(FavoritesResponse.fromJson(favourites[i])); + final favouritesData = service.data('types'); + if (favouritesData is List) { + for (var i = 0; i < favouritesData.length; i++) { + faves.add(FavoritesResponse.fromJson(favouritesData[i])); + } } + + // اضافه کردن مستقیم بخش فرصت و تهدید + faves.add(FavoritesResponse(id: 999, name: 'فرصت و تهدید', selected: false)); + selectedFavIds.clear(); for (var element in faves) { - if (element.selected!) { + if (element.selected == true) { selectedFavIds.add(element.id!); } } diff --git a/lib/views/customize_category/favorites_step.dart b/lib/views/customize_category/favorites_step.dart index 9a4a653..ff44291 100644 --- a/lib/views/customize_category/favorites_step.dart +++ b/lib/views/customize_category/favorites_step.dart @@ -78,29 +78,38 @@ class _FavoritesStepState extends State { asset: Assets.emptyChat, title: 'اولین نظر را بنویسید...', ), - builder: (context, state, index) => Center( - child: Container( - height: 48, - decoration: BoxDecoration( + builder: (context, state, index) => Column( + children: [ + Center( + child: Container( + height: 48, + decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), border: Border.all( - width: 1, - color: state.faves[index].selected! - ? Theme.of(context) - .colorScheme - .focusedBorder - : Theme.of(context).colorScheme.cardBorder), + width: 1, + color: state.faves[index].selected! + ? Theme.of(context).colorScheme.focusedBorder + : Theme.of(context).colorScheme.cardBorder + ), color: state.faves[index].selected! ? Theme.of(context).colorScheme.focused - : Theme.of(context).colorScheme.cardBorder), - child: CustomizeCategoryCheckbox( + : Theme.of(context).colorScheme.cardBorder + ), + child: CustomizeCategoryCheckbox( title: state.faves[index].name!, value: state.faves[index].selected, checkColor: Theme.of(context).colorScheme.checkFav, onChanged: (val) { state.changeSelected( - index, state.faves, state.selectedFavIds); - })), + index, state.faves, state.selectedFavIds); + } + ) + ), + ), + // Add extra bottom padding for the last item + if (index == state.faves.length - 1) + const SizedBox(height: 80), + ], ), ), ), @@ -129,4 +138,4 @@ class _FavoritesStepState extends State { ), ); } -} +} \ No newline at end of file