作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道有很多问题的标题类似 NoSuchMethodError: The method '#**something**#' was called on null.
通常当您尝试访问空对象的方法时会发生此问题。但是,就我而言,当我尝试将以下代码添加到我的 StatefulWidget
时会显示此异常:
_handleMyBusinessesTap() {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => PageBusinessList(
firebaseUser: widget.firebaseUser,
),
),
);
}
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: _buildAppBar(),
drawer: _buildDrawer(),
body: _buildBody(),
),
);
}
DefaultTabController
包含 3 页的正文:
Widget _buildBody() {
return TabBarView(
children: [
MyCardScreen(),
ReceivedScreen(),
SentScreen(),
],
);
}
_handleMyBusinessesTap
方法是我在抽屉中的选项之一,我想带我到一个新页面,但是由于某种原因,一旦我添加它,它就会在标题中抛出这个异常。有人遇到过这个问题并且知道应该如何处理吗?
Widget _buildDrawer() {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
UserAccountsDrawerHeader(
accountName: _buildAccountNameWidget(),
accountEmail: _buildAccountEmailWidget(),
currentAccountPicture: _buildAccountCircleAvatar(),
),
ListTile(title: Text("My Default Business Card"), onTap: _handleMyDefaultBusinessCardTap()),
ListTile(title: Text("My Businesses"), onTap: _handleMyBusinessesTap()),
ListTile(title: Text("Terms and Conditions"), onTap: _handleTermsAndConditionsTap()),
ListTile(title: Text("Privacy Policy"), onTap: _handlePrivacyPolicyTap()),
ListTile(title: Text("Log Out"), onTap: _handleLogOutTap()),
],
),
);
}
I/flutter ( 722): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 722): The following assertion was thrown building PageMain(dirty, dependencies: [_InheritedTheme,
I/flutter ( 722): _LocalizationsScope-[GlobalKey#b039d]], state: _PageMainWidgetState#e33af):
I/flutter ( 722): setState() or markNeedsBuild() called during build.
I/flutter ( 722): This Overlay widget cannot be marked as needing to build because the framework is already in the
I/flutter ( 722): process of building widgets. A widget can be marked as needing to be built during the build phase
I/flutter ( 722): only if one of its ancestors is currently building. This exception is allowed because the framework
I/flutter ( 722): builds parent widgets before children, which means a dirty descendant will always be built.
I/flutter ( 722): Otherwise, the framework might not visit this widget during this build phase.
I/flutter ( 722): The widget on which setState() or markNeedsBuild() was called was:
I/flutter ( 722): Overlay-[LabeledGlobalKey<OverlayState>#51a6b](state: OverlayState#7d0ac(entries:
I/flutter ( 722): [OverlayEntry#f42cb(opaque: false; maintainState: false), OverlayEntry#d6b18(opaque: false;
I/flutter ( 722): maintainState: true), OverlayEntry#75d78(opaque: false; maintainState: false),
I/flutter ( 722): OverlayEntry#02406(opaque: false; maintainState: true), OverlayEntry#8f4e5(opaque: false;
I/flutter ( 722): maintainState: false), OverlayEntry#11c40(opaque: false; maintainState: true)]))
I/flutter ( 722): The widget which was currently being built when the offending call was made was:
I/flutter ( 722): PageMain(dirty, dependencies: [_InheritedTheme, _LocalizationsScope-[GlobalKey#b039d]], state:
I/flutter ( 722): _PageMainWidgetState#e33af)
I/flutter ( 722): When the exception was thrown, this was the stack:
I/flutter ( 722): #0 Element.markNeedsBuild.<anonymous closure> (package:flutter/src/widgets/framework.dart:3503:11)
I/flutter ( 722): #1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:3529:6)
I/flutter ( 722): #2 State.setState (package:flutter/src/widgets/framework.dart:1133:14)
I/flutter ( 722): #3 OverlayState.insertAll (package:flutter/src/widgets/overlay.dart:346:5)
I/flutter ( 722): #4 OverlayRoute.install (package:flutter/src/widgets/routes.dart:43:24)
I/flutter ( 722): #5 TransitionRoute.install (package:flutter/src/widgets/routes.dart:180:11)
I/flutter ( 722): #6 ModalRoute.install (package:flutter/src/widgets/routes.dart:895:11)
I/flutter ( 722): #7 NavigatorState.push (package:flutter/src/widgets/navigator.dart:1742:11)
I/flutter ( 722): #8 _PageMainWidgetState._handleMyBusinessesTap (package:bizooc_client/pages/page_main.dart:86:27)
I/flutter ( 722): #9 _PageMainWidgetState._buildDrawer (package:bizooc_client/pages/page_main.dart:60:57)
I/flutter ( 722): #10 _PageMainWidgetState.build (package:bizooc_client/pages/page_main.dart:33:17)
I/flutter ( 722): #11 StatefulElement.build (package:flutter/src/widgets/framework.dart:3825:27)
I/flutter ( 722): #12 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3739:15)
I/flutter ( 722): #13 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #14 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3722:5)
I/flutter ( 722): #15 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3864:11)
I/flutter ( 722): #16 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3717:5)
I/flutter ( 722): #17 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #18 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #19 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter ( 722): #20 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #21 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #22 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #23 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #24 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3722:5)
I/flutter ( 722): #25 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3717:5)
I/flutter ( 722): #26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #27 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #28 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter ( 722): #29 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #30 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #31 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter ( 722): #32 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #33 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #34 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter ( 722): #35 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #36 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #37 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter ( 722): #38 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #39 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #40 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #41 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #42 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3722:5)
I/flutter ( 722): #43 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3864:11)
I/flutter ( 722): #44 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3717:5)
I/flutter ( 722): #45 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #46 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #47 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #48 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #49 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3722:5)
I/flutter ( 722): #50 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3717:5)
I/flutter ( 722): #51 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #52 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #53 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #54 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #55 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3722:5)
I/flutter ( 722): #56 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3864:11)
I/flutter ( 722): #57 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3717:5)
I/flutter ( 722): #58 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #59 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #60 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter ( 722): #61 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #62 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #63 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #64 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #65 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3722:5)
I/flutter ( 722): #66 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3717:5)
I/flutter ( 722): #67 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #68 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #69 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter ( 722): #70 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #71 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #72 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #73 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #74 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3722:5)
I/flutter ( 722): #75 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3864:11)
I/flutter ( 722): #76 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3717:5)
I/flutter ( 722): #77 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #78 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #79 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #80 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #81 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3722:5)
I/flutter ( 722): #82 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3717:5)
I/flutter ( 722): #83 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #84 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #85 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter ( 722): #86 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #87 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #88 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #89 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #90 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3722:5)
I/flutter ( 722): #91 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3717:5)
I/flutter ( 722): #92 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #93 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #94 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #95 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #96 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3722:5)
I/flutter ( 722): #97 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3864:11)
I/flutter ( 722): #98 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3717:5)
I/flutter ( 722): #99 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #100 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #101 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #102 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #103 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3722:5)
I/flutter ( 722): #104 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3864:11)
I/flutter ( 722): #105 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3717:5)
I/flutter ( 722): #106 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2961:14)
I/flutter ( 722): #107 Element.updateChild (package:flutter/src/widgets/framework.dart:2764:12)
I/flutter ( 722): #108 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4659:32)
I/flutter ( 722): #109 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4992:17)
I/flutter ( 722): #110 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15)
I/flutter ( 722): #111 _TheatreElement.update (package:flutter/src/widgets/overlay.dart:607:16)
I/flutter ( 722): #112 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15)
I/flutter ( 722): #113 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #114 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #115 StatefulElement.update (package:flutter/src/widgets/framework.dart:3894:5)
I/flutter ( 722): #116 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15)
I/flutter ( 722): #117 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #118 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #119 ProxyElement.update (package:flutter/src/widgets/framework.dart:4006:5)
I/flutter ( 722): #120 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15)
I/flutter ( 722): #121 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4883:14)
I/flutter ( 722): #122 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15)
I/flutter ( 722): #123 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #124 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #125 StatefulElement.update (package:flutter/src/widgets/framework.dart:3894:5)
I/flutter ( 722): #126 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15)
I/flutter ( 722): #127 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4883:14)
I/flutter ( 722): #128 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15)
I/flutter ( 722): #129 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4883:14)
I/flutter ( 722): #130 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15)
I/flutter ( 722): #131 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16)
I/flutter ( 722): #132 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter ( 722): #133 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2278:33)
I/flutter ( 722): #134 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:700:20)
I/flutter ( 722): #135 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5)
I/flutter ( 722): #136 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1012:15)
I/flutter ( 722): #137 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:952:9)
I/flutter ( 722): #138 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:864:5)
I/flutter ( 722): #142 _invoke (dart:ui/hooks.dart:219:10)
I/flutter ( 722): #143 _drawFrame (dart:ui/hooks.dart:178:3)
I/flutter ( 722): (elided 3 frames from package dart:async)
I/flutter ( 722): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter ( 722): Another exception was thrown: NoSuchMethodError: The getter 'status' was called on null.
I/flutter ( 722): Another exception was thrown: NoSuchMethodError: The method 'drive' was called on null.
最佳答案
这是使用回调函数时的常见错误。
ListTile(title: Text("Log Out"), onTap: _handleLogOutTap()),
ListTile(title: Text("Log Out"), onTap: _handleLogOutTap),
ListTile(title: Text("Log Out"), onTap: () => _handleLogOutTap()),
ListTile(title: Text("Log Out"), onTap: () { _handleLogOutTap() ; }),
ListTile
都一样的。
关于flutter - NoSuchMethodError : The method 'drive' was called on null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56329987/
我是一名优秀的程序员,十分优秀!