From 7ecf074bb8261d77c2565693551df8f4b75d89a3 Mon Sep 17 00:00:00 2001 From: MohammadTaha Basiri Date: Mon, 1 Apr 2024 19:34:59 +0330 Subject: [PATCH] Update new statistic and stats general state; clear old content before adding new In `new_statistic.dart`, updated the onTap function for a GestureDetector to clear old content before adding new content to the list. In `new_statistics_state.dart`, added a line to clear the contents list before adding new content to it. In `stat_cats_general_state.dart`, added a few lines to clear the contents list before adding new content to it. --- lib/views/home/new_statistic/new_statistic.dart | 10 +++++----- lib/views/home/new_statistic/new_statistics_state.dart | 2 ++ .../statistics_details/stat_cats_general_state.dart | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/views/home/new_statistic/new_statistic.dart b/lib/views/home/new_statistic/new_statistic.dart index 6684343..730681b 100644 --- a/lib/views/home/new_statistic/new_statistic.dart +++ b/lib/views/home/new_statistic/new_statistic.dart @@ -70,11 +70,11 @@ class _NewStatisticState extends State { ), GestureDetector( onTap: () => Future.delayed(Duration.zero, () { - Navigator.of(context).pushNamed(Routes.statGeneral, - arguments: { - "id": 7, - "title": state.contents[0].header - }); + Navigator.of(context) + .pushNamed(Routes.statGeneral, arguments: { + "id": 7, + "title": state.contents[0].header, + }).then((value) => state.getStatistic()); }), child: StatHeader(header: state.contents[0].header)), SizedBox( diff --git a/lib/views/home/new_statistic/new_statistics_state.dart b/lib/views/home/new_statistic/new_statistics_state.dart index b3d65e0..c0ccd66 100644 --- a/lib/views/home/new_statistic/new_statistics_state.dart +++ b/lib/views/home/new_statistic/new_statistics_state.dart @@ -22,6 +22,8 @@ class NewStatisticState extends CoreProvier { if (service.isSuccess) { final res = NewStatisticModel.fromJson(service.result); + contents.clear(); + for (var element in res.lists) { contents.add(element); } diff --git a/lib/views/home/new_statistic/statistics_details/stat_cats_general_state.dart b/lib/views/home/new_statistic/statistics_details/stat_cats_general_state.dart index bfc6154..ae4dd4c 100644 --- a/lib/views/home/new_statistic/statistics_details/stat_cats_general_state.dart +++ b/lib/views/home/new_statistic/statistics_details/stat_cats_general_state.dart @@ -1,4 +1,3 @@ - import 'package:didvan/models/enums.dart'; import 'package:didvan/models/new_statistic/general_item_model.dart'; import 'package:didvan/models/requests/newstats_general.dart'; @@ -40,6 +39,9 @@ class StatGeneralScreenState extends CoreProvier { await service.httpGet(); if (service.isSuccess) { final content = StatisticGeneralContent.fromJson(service.result); + + contents.clear(); + contents.addAll(content.contents); appState = AppState.idle;