请检查此github reposority ,您可以在其中找到所有 /em>所需的信息(代码,复制步骤,预期/实际结果,...)才能理解我的问题。
检查readme :)
此stackoverflow帖子地址什么是不起作用的?
但是,这是我问题的预览:
class ItemTile extends StatelessWidget {
const ItemTile({
Key? key,
required this.item,
}) : super(key: key);
final ItemModel item;
@override
Widget build(BuildContext context) {
return Provider(
create: (context) => ItemProvider(item: item),
child: ListTile(
onTap: () => Navigator.push(
context,
ItemDetailsPage(onNotification: MyPageRoute.onNotification(context), item: item),
),
title: const ItemTileTitle(),
),
);
}
}
class ItemTileTitle extends StatelessWidget {
const ItemTileTitle({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final item = context.select<ItemProvider, ItemModel>((provider) => provider.item);
return Text('ID: ${item.id}, Status: ${item.status}');
}
}
这种当前的小部件配置将不重建 itemtiletitle
nesk iteg> itemtile
tith 的父母重建不同/更新<代码>项目属性。
为什么这样?
我认为这是与小部件的生命周期相关的问题,以及 itemtile
如何不重建其子女 itemtiletitle
,因为没有什么在小部件树上确实发生了变化。只有提供商
的值更改。
但是,为什么 context.select
从构建
itemtiletitle的方法
如果提供者
的值改变了?
github存储库中的更多详细信息!:
也请给我有关我写这篇文章的方式的反馈,如果我做错了什么!谢谢您的帮助! :)
Please check this github repository, you can find there all the information needed (code, steps to reproduce, expected/actual results, ...) to understand my problem.
Check the README :)
This StackOverflow post addresses the What is not working?
section from the README file.
Nevertheless, here is a preview of my problem:
class ItemTile extends StatelessWidget {
const ItemTile({
Key? key,
required this.item,
}) : super(key: key);
final ItemModel item;
@override
Widget build(BuildContext context) {
return Provider(
create: (context) => ItemProvider(item: item),
child: ListTile(
onTap: () => Navigator.push(
context,
ItemDetailsPage(onNotification: MyPageRoute.onNotification(context), item: item),
),
title: const ItemTileTitle(),
),
);
}
}
class ItemTileTitle extends StatelessWidget {
const ItemTileTitle({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final item = context.select<ItemProvider, ItemModel>((provider) => provider.item);
return Text('ID: ${item.id}, Status: ${item.status}');
}
}
This current widget configuration will not rebuild the ItemTileTitle
whenever the ItemTile
's parent rebuilds with a different/updated item
property.
Why is that so?
I am thinking this is an issue related to the widget's lifecycle and how the ItemTile
will not rebuild its child ItemTileTitle
because nothing has really changed in the widget tree. Only the Provider
's value changed.
But then why is the context.select
from the build
method of ItemTileTitle
not rebuilding if the Provider
's value changed?
More details in the github repository!: https://github.com/HeyShafty/ErrorNotificationListener
Also please give me feedback on the way I wrote this post if I am doing anything wrong! Thank you for helping! :)
发布评论
评论(1)
使用
提供程序。Value
构造函数将成功触发重建。Using the
Provider.value
constructor will successfully trigger a rebuild.