我有一个全局ValueNotifer<MyType?> myNotifier
,它最初保存一个null
值。在一些API请求之后,它将异步更新,并将具有一个非空值MyType
。
我有一个方法myMethod
,它需要等待myNotifier
被初始化,然后才能执行某些操作。
Future<void> myMethod() async {
// How to wait for `myNotifier` to have a non-null value here?
assert(myNotifier.value != null, 'This requires myNotifier.value to be non-null');
// Perform some action with a non-null `myNotifier.value`.
}
字符串
如何等待myNotifier.value
为非空?
1条答案
按热度按时间mzmfm0qo1#
最后,我想出了这个解决方案:
字符串
这让我可以做到:
型