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:
parent
574151f0d8
commit
39ef54e52d
|
|
@ -21,7 +21,7 @@ class Content {
|
||||||
final String image;
|
final String image;
|
||||||
final String category;
|
final String category;
|
||||||
final String createdAt;
|
final String createdAt;
|
||||||
final bool marked;
|
bool marked;
|
||||||
|
|
||||||
final List<Tag> tags;
|
final List<Tag> tags;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,8 @@ class _InfographyScreenState extends State<InfographyScreen> {
|
||||||
itemCount: state.contents.length,
|
itemCount: state.contents.length,
|
||||||
itemBuilder: (context, index) => InfographyItem(
|
itemBuilder: (context, index) => InfographyItem(
|
||||||
id: state.contents[index].id,
|
id: state.contents[index].id,
|
||||||
onMarkChanged: state.changeMark,
|
onMarkChanged: (id, value, _) =>
|
||||||
|
state.changeMark(id, value),
|
||||||
image: state.contents[index].image,
|
image: state.contents[index].image,
|
||||||
category: state.contents[index].category,
|
category: state.contents[index].category,
|
||||||
createdAt: state.contents[index].createdAt,
|
createdAt: state.contents[index].createdAt,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
import 'package:didvan/constants/assets.dart';
|
import 'package:didvan/constants/assets.dart';
|
||||||
import 'package:didvan/models/category.dart';
|
import 'package:didvan/models/category.dart';
|
||||||
import 'package:didvan/models/enums.dart';
|
import 'package:didvan/models/enums.dart';
|
||||||
|
|
@ -40,6 +41,8 @@ class InfographyScreenState extends CoreProvier {
|
||||||
|
|
||||||
Future<void> changeMark(int id, bool value) async {
|
Future<void> changeMark(int id, bool value) async {
|
||||||
UserProvider.changeItemMark('infography', id, value);
|
UserProvider.changeItemMark('infography', id, value);
|
||||||
|
contents.firstWhereOrNull((element) => element.id == id)?.marked = value;
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getInfographyContent({required int page}) async {
|
Future<void> getInfographyContent({required int page}) async {
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ class InfographyItem extends StatelessWidget {
|
||||||
final String createdAt;
|
final String createdAt;
|
||||||
final int id;
|
final int id;
|
||||||
final bool marked;
|
final bool marked;
|
||||||
final Function onMarkChanged;
|
final void Function(int id, bool value, bool shouldUpdate) onMarkChanged;
|
||||||
|
|
||||||
const InfographyItem(
|
const InfographyItem(
|
||||||
{super.key,
|
{super.key,
|
||||||
|
|
@ -133,6 +133,7 @@ class InfographyItem extends StatelessWidget {
|
||||||
for (var i = 0; i < tag.length; i++)
|
for (var i = 0; i < tag.length; i++)
|
||||||
InfographyTag(
|
InfographyTag(
|
||||||
tag: tag[i],
|
tag: tag[i],
|
||||||
|
onMarkChanged: onMarkChanged,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
@ -151,7 +152,7 @@ class InfographyItem extends StatelessWidget {
|
||||||
type: 'infography',
|
type: 'infography',
|
||||||
gestureSize: 32,
|
gestureSize: 32,
|
||||||
value: marked,
|
value: marked,
|
||||||
onMarkChanged: (value) => onMarkChanged(id, value),
|
onMarkChanged: (value) => onMarkChanged(id, value, true),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,22 @@ import 'package:persian_number_utility/persian_number_utility.dart';
|
||||||
|
|
||||||
class InfographyTag extends StatelessWidget {
|
class InfographyTag extends StatelessWidget {
|
||||||
final Tag tag;
|
final Tag tag;
|
||||||
|
final void Function(int id, bool value, bool shouldUpdate) onMarkChanged;
|
||||||
|
|
||||||
const InfographyTag({
|
const InfographyTag({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.tag,
|
required this.tag,
|
||||||
|
required this.onMarkChanged,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return InkWrapper(
|
return InkWrapper(
|
||||||
borderRadius: DesignConfig.lowBorderRadius,
|
borderRadius: DesignConfig.lowBorderRadius,
|
||||||
onPressed: () => Navigator.of(context).pushNamed(Routes.hashtag,
|
onPressed: () =>
|
||||||
arguments: {
|
Navigator.of(context).pushNamed(Routes.hashtag, arguments: {
|
||||||
'tag': tag,
|
'tag': tag,
|
||||||
'onMarkChanged': () {},
|
'onMarkChanged': (int id, bool value) => onMarkChanged(id, value, true),
|
||||||
'type': 'infography'
|
'type': 'infography'
|
||||||
}),
|
}),
|
||||||
child: Container(
|
child: Container(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue