【问题标题】:The following NoSuchMethodError was thrown building MyApp(dirty, state: _MyAppState#86032):在构建 MyApp(dirty, state: _MyAppState#86032) 时引发了以下 NoSuchMethodError:
【发布时间】:2022-01-24 15:26:56
【问题描述】:

我收到此错误消息,但不知道如何解决它:

小部件库捕获的异常 在构建 MyApp(dirty, state: _MyAppState#86032) 时引发了以下 NoSuchMethodError:

The method 'call' was called on null.

Receiver: null

Tried calling: call(Instance of 'ChangeNotifierProvider<UserLoggedIn>')```

这是导致此问题的代码:

void main() {
    runApp(ProviderScope(child:MyApp()));
 }

class MyApp extends StatefulHookWidget {

 @override
 _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp>

我认为我应该更改当前使用的 Flutter 版本,因为这发生在我更新 Flutter 时,但没有奏效。

【问题讨论】:

  • 是否通过将MyApp 设置为 statelessWidget 或 statefulWidget 来实现?
  • 嘿Yeasin,我的问题仍然存在。它发生在 statefulWidget。

标签: flutter dart dart-null-safety


【解决方案1】:

听起来您可能已将 Flutter 更新为具有空安全性的版本。 发生这种情况时,即使在以前版本的颤振中方法正常并运行,方法也不能为空。 看看这些参考资料: Null Safety

Migration

【讨论】:

  • 嘿尼克,我已经迁移了我的代码,但问题仍然存在。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-10
  • 2021-09-18
  • 2021-02-16
相关资源
最近更新 更多