- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的项目中,当 ChangeNotifier
类收到一个状态,它设置一个 bool 值并调用 notifyListeners()
.在我的主要 build()
函数,然后我检查pending-boolean并相应地显示对话框 - 但我只能通过在构建方法中给它一个小的延迟来显示对话框 - 似乎缺少上下文。
TL;博士:
有什么方法可以从 ChangeNotifier
中显示对话框类(class)?
最佳答案
即使你可以通过传递 BuildContext
来做到这一点。 ,你不应该,因为你会耦合你的 ChangeNotifier
仅适用于特定情况。
假设这是您的模型:
class Model extends ChangeNotifier {
bool _loading = false;
bool get loading => _loading;
void update(bool value) {
_loading = value;
notifyListeners();
}
}
loading
按下按钮时使用的值:
final model = Provider.of<Model>(context, listen: false);
model.update(true);
final model = Provider.of<Model>(context);
if (model.loading) {
// show dialog
}
关于flutter - 如何从 ChangeNotifier 模型显示对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61891242/
我是 Flutter 新手,并且一直坚持这个我有一个页面使用名为 GoogleMapsNotifier 和 ChangeNotifier 的类,当我弹出页面时,我想在该类中处理 Stream(最后一个
从文档中我了解到,可以在 ChangeNotifier 上调用 addListener()实例将自定义监听器添加到堆栈中。 此方法接受零参数的回调(根据 notifyListeners() ),例如:
在flutter sample在解释如何使用 Provider 包时,有两个模型,Catalog 和 Model。对于 Catalog 模型,不使用 ChangeNotifier,但对于 Cart 模
在flutter sample在解释如何使用 Provider 包时,有两个模型,Catalog 和 Model。对于 Catalog 模型,不使用 ChangeNotifier,但对于 Cart 模
ChangeNotifier 的 flutter 文档说 ChangeNotifier is optimized for small numbers (one or two) of listeners
在我的项目中,当 ChangeNotifier类收到一个状态,它设置一个 bool 值并调用 notifyListeners() .在我的主要 build()函数,然后我检查pending-boole
我使用Provider / ChangenNotifier模式来处理状态,如in the official docs所述。 我有一个状态字段,要在构建小部件后设置。但是,如果我尝试在build方法中进
我在StackoverFlow中四处张望,却找不到自己的解决方案。 场景: 我有一个带有ChangeNotifier类的Flutter SharedPreferences提供程序,它将使用当前的“登录
当我在提供程序类中调用此对象的一个项目时,我调用一个 api 并将其结果放入一个对象中,但是当我从提供程序类中调用此变量时,有时它被填充但有时它为空。如何? 我这样称呼这个提供者类 await
我在 Model 中有要执行的代码。我使用 Provider 提供 Model。但是如果 Model 在完成执行之前被释放,我会得到错误: E/flutter (26180): [ERROR:flut
背景 ValueNotifier 有一个 ValueListenableBuilder 小部件。 Stream 有一个 StreamBuilder 小部件。 Future 有一个 FutureBuil
我想为我的应用程序实现 Provider,在做了一些研究之后,我发现我必须为我的 Data 类实现 ChangeNotifier 才能在“天”更改时更新 UI。 我见过有人在 setter 方法中编写
情况:我正在看一个带有 Win32::ChangeNotify 的文件夹(这里不关心跨平台)。该文件夹共享到本地网络。将从另一台计算机在此文件夹中创建一个文件。这个过程需要一些时间。 问题:当文件仍在
我有一个 sqlite 数据库,我从中读取数据。我还有一棵很长的小部件树。因此,经过一些研究,我找到了 provider Flutter 包。但是我不知道如何在扩展 ChangeNotifier 的类
我安装了 File::ChangeNotify在 Windows 系统上并尝试运行以下代码: my $watcher = File::ChangeNotify->instantiate_wa
在我的 Flutter 应用程序中,我有一个小部件 class HomeScreen extends StatelessWidget 使用模型 class HomeScreenModel extend
#!/opt/perl_5.18.2/linux50/bin/perl use strict; #use warnings; use File::ChangeNotify; $| = 1; my $w
我有一个 ChangeNotifier,我想在多个路由之间共享它,但不是所有路由: Page1 是我的第一页。我只需要与 Page2、Page3 和 Page 共享 ChangeNotifierPro
#!/opt/perl_5.18.2/linux50/bin/perl use strict; #use warnings; use File::ChangeNotify; $| = 1; my $w
我想将我的整个项目从 provider 转移到 riverpod。但我卡在了这一点上。 class EditQuestionScreen extends StatelessWidget { Edi
我是一名优秀的程序员,十分优秀!