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/constants/app_icons.dart';
import 'package:didvan/models/new_statistic/new_statistics_model.dart'; import 'package:didvan/models/new_statistic/new_statistics_model.dart';
import 'package:didvan/providers/theme.dart'; import 'package:didvan/providers/theme.dart';
import 'package:didvan/providers/user.dart';
import 'package:didvan/routes/routes.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/new_statistics_state.dart';
import 'package:didvan/views/home/new_statistic/widgets/statistic_cat.dart'; import 'package:didvan/views/home/new_statistic/widgets/statistic_cat.dart';
@ -78,15 +79,18 @@ class _NewStatisticState extends State<NewStatistic> {
}), }),
child: StatHeader(header: state.contents[0].header)), child: StatHeader(header: state.contents[0].header)),
SizedBox( SizedBox(
height: 100, height: 100,
width: 80, width: 80,
child: ListView.builder( child: ListView.builder(
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
shrinkWrap: true, shrinkWrap: true,
physics: const ScrollPhysics(), physics: const ScrollPhysics(),
itemCount: state.contents[0].contents.length, itemCount: state.contents[0].contents.length,
itemBuilder: (context, index) => StatMainCard( itemBuilder: (context, index) => StatMainCard(
statistic: state.contents[0].contents[index]))), statistic: state.contents[0].contents[index],
),
),
),
const DidvanDivider( const DidvanDivider(
verticalPadding: 4, verticalPadding: 4,
), ),
@ -219,6 +223,8 @@ class StatMainCard extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final state = context.read<NewStatisticState>();
return GestureDetector( return GestureDetector(
onTap: () => id != 5 onTap: () => id != 5
? Navigator.of(context) ? Navigator.of(context)
@ -227,7 +233,7 @@ class StatMainCard extends StatelessWidget {
'label': statistic.label, 'label': statistic.label,
'title': statistic.title, 'title': statistic.title,
'marked': statistic.marked, 'marked': statistic.marked,
}) }).then((value) => state.getStatistic())
: null, : null,
child: Padding( child: Padding(
padding: const EdgeInsets.all(4.0), 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 { class StatHeader extends StatelessWidget {

View File

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