Infography content model property 'marked' changed to be mutable, and related UI updates

* In `infography_content.dart`, the `marked` property of `Content` is changed from `final` to a mutable `bool`.
* In `infography_screen.dart`, the `onMarkChanged` callback in `InfographyItem` is updated to accept an additional `bool shouldUpdate` parameter, and the callback is called with the new signature in `InfographyScreenState`.
* In `infography_item.dart`, the `onMarkChanged` callback in `InfographyTag` is updated to accept an additional `bool shouldUpdate` parameter.
* In `infography_tag.dart`, the `onPressed` callback in `InfographyTag` is updated to pass the `onMarkChanged` callback with the new signature to the `HashtagScreen`.
This commit is contained in:
MohammadTaha Basiri 2024-04-01 19:01:46 +03:30
parent 574151f0d8
commit 39ef54e52d
5 changed files with 17 additions and 10 deletions

View File

@ -21,7 +21,7 @@ class Content {
final String image;
final String category;
final String createdAt;
final bool marked;
bool marked;
final List<Tag> tags;

View File

@ -178,7 +178,8 @@ class _InfographyScreenState extends State<InfographyScreen> {
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,

View File

@ -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<void> changeMark(int id, bool value) async {
UserProvider.changeItemMark('infography', id, value);
contents.firstWhereOrNull((element) => element.id == id)?.marked = value;
update();
}
Future<void> getInfographyContent({required int page}) async {

View File

@ -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),
),
],
)

View File

@ -10,20 +10,22 @@ 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: {
onPressed: () =>
Navigator.of(context).pushNamed(Routes.hashtag, arguments: {
'tag': tag,
'onMarkChanged': () {},
'onMarkChanged': (int id, bool value) => onMarkChanged(id, value, true),
'type': 'infography'
}),
child: Container(