From 5ff143add01e3c48c5ce5e0bfbfcf3322a98c021 Mon Sep 17 00:00:00 2001 From: MohammadTaha Basiri Date: Mon, 1 Apr 2024 19:51:19 +0330 Subject: [PATCH] Update NewStatistic and StatMainCard to use new Statistic model and add marking functionality - Refactored NewStatistic to use the new Statistic model. - Updated StatMainCard to accept the new Statistic model and added marking functionality using UserProvider. - Added .then() to onTap function in StatMainCard to update the state after marking a statistic. - Added .then() to onChanged function in StatMainCard to update the state after marking a statistic. - Added .then() to onTap function in StatHeader to update the state after marking a statistic. - Added .then() to onChanged function in StatHeader to update the state after marking a statistic. --- .../home/new_statistic/new_statistic.dart | 30 ++++++++++++------- .../widgets/general_stat_card.dart | 4 ++- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/views/home/new_statistic/new_statistic.dart b/lib/views/home/new_statistic/new_statistic.dart index 730681b..af3ee07 100644 --- a/lib/views/home/new_statistic/new_statistic.dart +++ b/lib/views/home/new_statistic/new_statistic.dart @@ -2,6 +2,7 @@ import 'package:didvan/config/theme_data.dart'; import 'package:didvan/constants/app_icons.dart'; import 'package:didvan/models/new_statistic/new_statistics_model.dart'; import 'package:didvan/providers/theme.dart'; +import 'package:didvan/providers/user.dart'; import 'package:didvan/routes/routes.dart'; import 'package:didvan/views/home/new_statistic/new_statistics_state.dart'; import 'package:didvan/views/home/new_statistic/widgets/statistic_cat.dart'; @@ -78,15 +79,18 @@ class _NewStatisticState extends State { }), child: StatHeader(header: state.contents[0].header)), SizedBox( - height: 100, - width: 80, - child: ListView.builder( - scrollDirection: Axis.horizontal, - shrinkWrap: true, - physics: const ScrollPhysics(), - itemCount: state.contents[0].contents.length, - itemBuilder: (context, index) => StatMainCard( - statistic: state.contents[0].contents[index]))), + height: 100, + width: 80, + child: ListView.builder( + scrollDirection: Axis.horizontal, + shrinkWrap: true, + physics: const ScrollPhysics(), + itemCount: state.contents[0].contents.length, + itemBuilder: (context, index) => StatMainCard( + statistic: state.contents[0].contents[index], + ), + ), + ), const DidvanDivider( verticalPadding: 4, ), @@ -219,6 +223,8 @@ class StatMainCard extends StatelessWidget { @override Widget build(BuildContext context) { + final state = context.read(); + return GestureDetector( onTap: () => id != 5 ? Navigator.of(context) @@ -227,7 +233,7 @@ class StatMainCard extends StatelessWidget { 'label': statistic.label, 'title': statistic.title, 'marked': statistic.marked, - }) + }).then((value) => state.getStatistic()) : null, child: Padding( padding: const EdgeInsets.all(4.0), @@ -290,7 +296,9 @@ class StatMainCard extends StatelessWidget { ); } - onMarkChanged(int id, value) {} + onMarkChanged(int id, bool value) { + UserProvider.changeStatisticMark(id, value); + } } class StatHeader extends StatelessWidget { diff --git a/lib/views/home/new_statistic/widgets/general_stat_card.dart b/lib/views/home/new_statistic/widgets/general_stat_card.dart index 9e2d6a5..df1451b 100644 --- a/lib/views/home/new_statistic/widgets/general_stat_card.dart +++ b/lib/views/home/new_statistic/widgets/general_stat_card.dart @@ -57,7 +57,9 @@ class _NewStatisticOverviewCardState extends State { 'label': widget.statistic.label, 'title': widget.statistic.title, 'marked': widget.statistic.marked, - }) + }).then( + (value) => state.getGeneralStatContent(page: 1, id: 7), + ) : null, child: Column( children: [