diff --git a/lib/models/infography/infography_content.dart b/lib/models/infography/infography_content.dart index efa21a1..747deec 100644 --- a/lib/models/infography/infography_content.dart +++ b/lib/models/infography/infography_content.dart @@ -21,7 +21,7 @@ class Content { final String image; final String category; final String createdAt; - final bool marked; + bool marked; final List tags; diff --git a/lib/views/home/infography/infography_screen.dart b/lib/views/home/infography/infography_screen.dart index 19f6f13..b1957c4 100644 --- a/lib/views/home/infography/infography_screen.dart +++ b/lib/views/home/infography/infography_screen.dart @@ -178,7 +178,8 @@ class _InfographyScreenState extends State { itemCount: state.contents.length, itemBuilder: (context, index) => InfographyItem( id: state.contents[index].id, - onMarkChanged: state.changeMark, + onMarkChanged: (id, value, _) => + state.changeMark(id, value), image: state.contents[index].image, category: state.contents[index].category, createdAt: state.contents[index].createdAt, diff --git a/lib/views/home/infography/infography_screen_state.dart b/lib/views/home/infography/infography_screen_state.dart index ee3e9b3..43756d0 100644 --- a/lib/views/home/infography/infography_screen_state.dart +++ b/lib/views/home/infography/infography_screen_state.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:didvan/constants/assets.dart'; import 'package:didvan/models/category.dart'; import 'package:didvan/models/enums.dart'; @@ -40,6 +41,8 @@ class InfographyScreenState extends CoreProvier { Future changeMark(int id, bool value) async { UserProvider.changeItemMark('infography', id, value); + contents.firstWhereOrNull((element) => element.id == id)?.marked = value; + update(); } Future getInfographyContent({required int page}) async { diff --git a/lib/views/home/main/widgets/infography_item.dart b/lib/views/home/main/widgets/infography_item.dart index 5862628..69fbb1a 100644 --- a/lib/views/home/main/widgets/infography_item.dart +++ b/lib/views/home/main/widgets/infography_item.dart @@ -54,7 +54,7 @@ class InfographyItem extends StatelessWidget { final String createdAt; final int id; final bool marked; - final Function onMarkChanged; + final void Function(int id, bool value, bool shouldUpdate) onMarkChanged; const InfographyItem( {super.key, @@ -133,6 +133,7 @@ class InfographyItem extends StatelessWidget { for (var i = 0; i < tag.length; i++) InfographyTag( tag: tag[i], + onMarkChanged: onMarkChanged, ), ], ), @@ -151,7 +152,7 @@ class InfographyItem extends StatelessWidget { type: 'infography', gestureSize: 32, value: marked, - onMarkChanged: (value) => onMarkChanged(id, value), + onMarkChanged: (value) => onMarkChanged(id, value, true), ), ], ) diff --git a/lib/views/widgets/infography_tag.dart b/lib/views/widgets/infography_tag.dart index 393a366..f61c80f 100644 --- a/lib/views/widgets/infography_tag.dart +++ b/lib/views/widgets/infography_tag.dart @@ -10,22 +10,24 @@ import 'package:persian_number_utility/persian_number_utility.dart'; class InfographyTag extends StatelessWidget { final Tag tag; + final void Function(int id, bool value, bool shouldUpdate) onMarkChanged; const InfographyTag({ Key? key, required this.tag, + required this.onMarkChanged, }) : super(key: key); @override Widget build(BuildContext context) { return InkWrapper( borderRadius: DesignConfig.lowBorderRadius, - onPressed: () => Navigator.of(context).pushNamed(Routes.hashtag, - arguments: { - 'tag': tag, - 'onMarkChanged': () {}, - 'type': 'infography' - }), + onPressed: () => + Navigator.of(context).pushNamed(Routes.hashtag, arguments: { + 'tag': tag, + 'onMarkChanged': (int id, bool value) => onMarkChanged(id, value, true), + 'type': 'infography' + }), child: Container( padding: const EdgeInsets.symmetric( vertical: 4,