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:
parent
7ecf074bb8
commit
5ff143add0
|
|
@ -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<NewStatistic> {
|
|||
}),
|
||||
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<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 {
|
||||
|
|
|
|||
|
|
@ -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: [
|
||||
|
|
|
|||
Loading…
Reference in New Issue