From 6853af3d21ef93953e75989c237977d94d0e6e54 Mon Sep 17 00:00:00 2001 From: MohammadTaha Basiri Date: Thu, 21 Apr 2022 15:17:48 +0430 Subject: [PATCH] bug fixes --- lib/views/home/comments/comments_state.dart | 5 +++ lib/views/home/statistic/statistic.dart | 16 ++++++--- lib/views/home/statistic/statistic_state.dart | 33 ++++++------------- lib/views/widgets/didvan/app_bar.dart | 1 + lib/views/widgets/didvan/scaffold.dart | 10 ++++-- 5 files changed, 34 insertions(+), 31 deletions(-) diff --git a/lib/views/home/comments/comments_state.dart b/lib/views/home/comments/comments_state.dart index c71b79e..03e04bc 100644 --- a/lib/views/home/comments/comments_state.dart +++ b/lib/views/home/comments/comments_state.dart @@ -195,6 +195,11 @@ class CommentsState extends CoreProvier { ); } comments.remove(comment); + } else { + comments + .firstWhere((element) => element.id == rootId) + .replies + .removeWhere((element) => element.id == id); } notifyListeners(); } diff --git a/lib/views/home/statistic/statistic.dart b/lib/views/home/statistic/statistic.dart index 1651395..6496e79 100644 --- a/lib/views/home/statistic/statistic.dart +++ b/lib/views/home/statistic/statistic.dart @@ -11,6 +11,7 @@ import 'package:didvan/views/home/widgets/categories_gird.dart'; import 'package:didvan/views/home/widgets/categories_list.dart'; import 'package:didvan/views/home/widgets/logo_app_bar.dart'; import 'package:didvan/views/widgets/animated_visibility.dart'; +import 'package:didvan/views/widgets/didvan/divider.dart'; import 'package:didvan/views/widgets/didvan/text.dart'; import 'package:didvan/views/widgets/state_handlers/empty_list.dart'; import 'package:didvan/views/widgets/state_handlers/sliver_state_handler.dart'; @@ -61,7 +62,8 @@ class _StatisticState extends State { const SliverToBoxAdapter( child: SizedBox(height: 180), ), - if (state.appState != AppState.failed) + if (state.appState != AppState.failed && + state.markedStatistics.isNotEmpty) SliverPadding( padding: const EdgeInsets.only(right: 16, bottom: 20), sliver: SliverToBoxAdapter( @@ -80,7 +82,7 @@ class _StatisticState extends State { ), ), SliverStateHandler( - onRetry: () => state.getStatistic(page: state.page), + onRetry: state.getStatistic, state: state, itemPadding: const EdgeInsets.only( bottom: 20, @@ -91,12 +93,16 @@ class _StatisticState extends State { enableEmptyState: _itemCount(state) == 0, placeholder: StatisticOverview.placeHolder, builder: (context, state, index) { + if (index == state.markedStatistics.length) { + return const DidvanDivider(verticalPadding: 8); + } bool isMarked = false; StatisticData statistic; if (index < state.markedStatistics.length) { isMarked = true; statistic = state.markedStatistics[index]; } else { + index--; statistic = state.statistics[index - state.markedStatistics.length]; } @@ -106,7 +112,7 @@ class _StatisticState extends State { onMarkChanged: state.changeMark, ); }, - childCount: _itemCount(state), + childCount: _itemCount(state) + 1, ), SliverToBoxAdapter( child: SizedBox( @@ -136,7 +142,7 @@ class _StatisticState extends State { isColapsed: state.isColapsed, onSelected: (id) { state.selectedCategoryId = id; - state.getStatistic(page: 1); + state.getStatistic(); }, selectedCats: state.selectedCategory == null ? [] @@ -157,7 +163,7 @@ class _StatisticState extends State { if (category.id != 0) { state.selectedCategoryId = category.id; } - state.getStatistic(page: 1); + state.getStatistic(); } void _handleAnimations([bool forceAnimate = false]) async { diff --git a/lib/views/home/statistic/statistic_state.dart b/lib/views/home/statistic/statistic_state.dart index 19d7883..00f6c9f 100644 --- a/lib/views/home/statistic/statistic_state.dart +++ b/lib/views/home/statistic/statistic_state.dart @@ -9,7 +9,6 @@ import 'package:didvan/services/network/request.dart'; import 'package:didvan/services/network/request_helper.dart'; class StatisticState extends CoreProvier { - int page = 1; bool isScrolled = false; bool shouldColapse = false; int selectedCategoryId = -1; @@ -25,24 +24,10 @@ class StatisticState extends CoreProvier { bool get isCategorySelected => selectedCategoryId != 0; - void resetFilters(bool isInit) { - selectedCategoryId = 0; - isScrolled = false; - if (!isInit) { - getStatistic(page: 1); - } - } - - Future getStatistic({ - required int page, - }) async { - this.page = page; - if (this.page == page) { - statistics.clear(); - } - if (page == 1) { - appState = AppState.busy; - } + Future getStatistic() async { + statistics.clear(); + markedStatistics.clear(); + appState = AppState.busy; final RequestService service = RequestService( RequestHelper.statisticOverviews( selectedCategoryId == 0 || selectedCategoryId == 1 @@ -58,7 +43,7 @@ class StatisticState extends CoreProvier { } final marked = service.result['marked']; for (var i = 0; i < marked.length; i++) { - statistics.add(StatisticData.fromJson(marked[i])); + markedStatistics.add(StatisticData.fromJson(marked[i])); } if (isColapsed || isCategorySelected) { shouldColapse = true; @@ -66,7 +51,6 @@ class StatisticState extends CoreProvier { appState = AppState.idle; return; } - appState = AppState.failed; } @@ -85,9 +69,12 @@ class StatisticState extends CoreProvier { } void init() { - resetFilters(true); + selectedCategoryId = 0; + isScrolled = false; + markedStatistics.clear(); + statistics.clear(); Future.delayed(Duration.zero, () { - getStatistic(page: 1); + getStatistic(); }); categories = [ CategoryData( diff --git a/lib/views/widgets/didvan/app_bar.dart b/lib/views/widgets/didvan/app_bar.dart index 81770c8..ab7a949 100644 --- a/lib/views/widgets/didvan/app_bar.dart +++ b/lib/views/widgets/didvan/app_bar.dart @@ -29,6 +29,7 @@ class DidvanAppBar extends StatelessWidget { ), ) : null, + color: backgroundColor ?? Theme.of(context).colorScheme.background, ), child: Row( children: [ diff --git a/lib/views/widgets/didvan/scaffold.dart b/lib/views/widgets/didvan/scaffold.dart index 38f9dde..879e240 100644 --- a/lib/views/widgets/didvan/scaffold.dart +++ b/lib/views/widgets/didvan/scaffold.dart @@ -59,11 +59,15 @@ class _DidvanScaffoldState extends State { SliverAppBar( toolbarHeight: (widget.appBarData!.isSmall ? 56 : 72) - statusBarHeight, - backgroundColor: widget.backgroundColor ?? - Theme.of(context).colorScheme.background, automaticallyImplyLeading: false, pinned: true, - flexibleSpace: DidvanAppBar(appBarData: widget.appBarData!), + backgroundColor: widget.backgroundColor ?? + Theme.of(context).colorScheme.background, + flexibleSpace: DidvanAppBar( + appBarData: widget.appBarData!, + backgroundColor: widget.backgroundColor ?? + Theme.of(context).colorScheme.background, + ), ), if (widget.children != null && !widget.showSliversFirst) SliverPadding(