Flutter:抛出 NoSuchMethodError。 getter 'type' 被调用为 null
Flutter: NoSuchMethodError was thrown. The getter 'type' was called on null
您好,我目前正在使用 Flutter 开发移动应用程序。我的程序有两种类型的用户,所以我需要根据数据类型来调整用户。因此,在检查用户数据时,抛出了一个 NoSuchMethodError,指出 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
正如异常告诉您的那样,您正在对 null 调用 type
,这意味着在某个时刻 profile
为 null,并且您正试图对其调用 type
。您只需要在尝试使用它之前检查 profile
是否不为 null
您好,我目前正在使用 Flutter 开发移动应用程序。我的程序有两种类型的用户,所以我需要根据数据类型来调整用户。因此,在检查用户数据时,抛出了一个 NoSuchMethodError,指出 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
正如异常告诉您的那样,您正在对 null 调用 type
,这意味着在某个时刻 profile
为 null,并且您正试图对其调用 type
。您只需要在尝试使用它之前检查 profile
是否不为 null