【发布时间】:2021-08-14 19:23:31
【问题描述】:
您好,我目前正在使用 Flutter 开发移动应用。我的程序有两种类型的用户,所以我需要根据数据类型来调整用户。因此,在检查用户数据时,会抛出 NoSuchMethodError 说明在继续之前在红屏上的 null 上调用了 getter 一秒钟。但对象不为空。我不知道还能做什么。任何人都可以帮助我:( 2s 异常让我烦恼......
final profile = Provider.of<Profile>(context);
if (profile.type == null) {
return Center(
child: CircularProgressIndicator(
backgroundColor: Colors.white,
),
);
} else {
return MaterialApp(
home: profile.type ? SessionWrapperTutor() : SessionWrapperTutee(), //here the problem occur
);
这是错误
════════ Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building HomeWrapper(dirty, dependencies: [InheritedProvider<Profile>], state: _HomeWrapperState#91be8):
The getter 'type' was called on null.
Receiver: null
Tried calling: type
The relevant error-causing widget was HomeWrapper
When the exception was thrown, this was the stack
#0 Object.noSuchMethod
#1 _HomeWrapperState.build
#2 StatefulElement.build
#3 ComponentElement.performRebuild
#4 StatefulElement.performRebuild
【问题讨论】:
-
非常感谢您!我不能 .isEmpty 因为配置文件是对象。但已经找到解决方案。谢谢你的建议! :)
标签: firebase flutter dart flutter-dependencies flutter-provider