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.
This commit is contained in:
MohammadTaha Basiri 2024-04-01 19:51:19 +03:30
parent 7ecf074bb8
commit 5ff143add0
2 changed files with 22 additions and 12 deletions

View File

@ -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';
@ -86,7 +87,10 @@ class _NewStatisticState extends State<NewStatistic> {
physics: const ScrollPhysics(),
itemCount: state.contents[0].contents.length,
itemBuilder: (context, index) => StatMainCard(
statistic: state.contents[0].contents[index]))),
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<NewStatisticState>();
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 {

View File

@ -57,7 +57,9 @@ class _NewStatisticOverviewCardState extends State<NewStatisticOverviewCard> {
'label': widget.statistic.label,
'title': widget.statistic.title,
'marked': widget.statistic.marked,
})
}).then(
(value) => state.getGeneralStatContent(page: 1, id: 7),
)
: null,
child: Column(
children: [