I know there are quite a few questions that have a resembling title of NoSuchMethodError: The method '#**something**#' was called on null.
And usually this issue happens when you try to access a null object's method. But, in my case this Exception is shown when I try to add the following code to my StatefulWidget
:
_handleMyBusinessesTap() {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => PageBusinessList(
firebaseUser: widget.firebaseUser,
),
),
);
}
Once I try to use the Navigator object in my code I'm getting this exception. The only difference I can think of that I have in this page from the other pages in which Navigator object does not causes any issues is that I build my page this way:
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: _buildAppBar(),
drawer: _buildDrawer(),
body: _buildBody(),
),
);
}
I'm using here DefaultTabController
contains a body of 3 page:
Widget _buildBody() {
return TabBarView(
children: [
MyCardScreen(),
ReceivedScreen(),
SentScreen(),
],
);
}
The _handleMyBusinessesTap
method is one of the options I have in the drawer which I want to take me to a new page, but for some reason once I add it it throws this exception in the title. Does someone encountered this problem and know how it should be handled?
here is the buildDrawer method:
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()),
],
),
);
}
here is there rest of the stack:
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.
This is a common error when use callbacks functions.
ListTile(title: Text("Log Out"), onTap: _handleLogOutTap()),
To fix your issue you have some options :
1-
ListTile(title: Text("Log Out"), onTap: _handleLogOutTap),
2-
ListTile(title: Text("Log Out"), onTap: () => _handleLogOutTap()),
3-
ListTile(title: Text("Log Out"), onTap: () { _handleLogOutTap() ; }),
The same for all of your ListTile
's.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With