Flutter Bottom Navigation Bar not working
up vote
0
down vote
favorite
I am trying to use the BottomNavigationBar
in Flutter, however it is giving me a weird error that seem to have no reference to my code and I am not able to find this error anywhere online. In fact every tutorial, page, or question I can find says to do it this way.
Here is my code from home.dart
:
... Imports ...
class HomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return HomePageState();
}
}
class HomePageState extends State<HomePage> {
int _selectedTab = 0;
final _pageOptions = [
HomePage(),
CatPage(),
SearchPage(),
];
void _onItemTapped(int index) {
setState(() {
_selectedTab = index;
});
print(index);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Loopt In'),
),
body: _pageOptions[_selectedTab],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedTab,
onTap: _onItemTapped,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.category),
title: Text('Categories'),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
title: Text('Search'),
),
],
),
);
}
}
Interestingly enough when I change the _pageOptions
array to have a Text()
widgets instead of widgets that I made it work fine, but I don't know why and need it to work with my widgets obviously.
Here's the error I'm getting:
[VERBOSE-2:shell.cc(181)] Dart Error: Unhandled exception:
'package:flutter/src/widgets/framework.dart': Failed assertion: line 2257 pos 20: '_debugCurrentBuildTarget == context': is not true.
#0 _AssertionError._doThrowNew (dart:core/runtime/liberrors_patch.dart:40:39)
#1 _AssertionError._throwNew (dart:core/runtime/liberrors_patch.dart:36:5)
#2 BuildOwner.buildScope.<anonymous closure> (package:flutter/src/widgets/framework.dart:2257:20)
#3 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2261:12)
#4 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:817:13)
#5 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:709:7)
#6 runApp (package:flutter/src/widgets/binding.dart:748:7)
#7 main (file:///Users/garrettlove/Documents/learn/Flutter/loopt_in/lib/main.d<…>
dart flutter
|
show 5 more comments
up vote
0
down vote
favorite
I am trying to use the BottomNavigationBar
in Flutter, however it is giving me a weird error that seem to have no reference to my code and I am not able to find this error anywhere online. In fact every tutorial, page, or question I can find says to do it this way.
Here is my code from home.dart
:
... Imports ...
class HomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return HomePageState();
}
}
class HomePageState extends State<HomePage> {
int _selectedTab = 0;
final _pageOptions = [
HomePage(),
CatPage(),
SearchPage(),
];
void _onItemTapped(int index) {
setState(() {
_selectedTab = index;
});
print(index);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Loopt In'),
),
body: _pageOptions[_selectedTab],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedTab,
onTap: _onItemTapped,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.category),
title: Text('Categories'),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
title: Text('Search'),
),
],
),
);
}
}
Interestingly enough when I change the _pageOptions
array to have a Text()
widgets instead of widgets that I made it work fine, but I don't know why and need it to work with my widgets obviously.
Here's the error I'm getting:
[VERBOSE-2:shell.cc(181)] Dart Error: Unhandled exception:
'package:flutter/src/widgets/framework.dart': Failed assertion: line 2257 pos 20: '_debugCurrentBuildTarget == context': is not true.
#0 _AssertionError._doThrowNew (dart:core/runtime/liberrors_patch.dart:40:39)
#1 _AssertionError._throwNew (dart:core/runtime/liberrors_patch.dart:36:5)
#2 BuildOwner.buildScope.<anonymous closure> (package:flutter/src/widgets/framework.dart:2257:20)
#3 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2261:12)
#4 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:817:13)
#5 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:709:7)
#6 runApp (package:flutter/src/widgets/binding.dart:748:7)
#7 main (file:///Users/garrettlove/Documents/learn/Flutter/loopt_in/lib/main.d<…>
dart flutter
do you have HomePage inside HomePage ? HomePage(), CatPage(), SearchPage(),
– diegoveloper
Nov 11 at 2:32
@diegoveloper I'm not really sure what you mean. What i posted is my entire HomePage. CatPage() and SearchPage() currently only return Text() widgets
– Garrett
Nov 11 at 2:35
I mean, your main widget is : HomePage , then in your _pageOptions var I see [HomePage(), CatPage(), SearchPage()] , why are you calling HomePage again inside HomePage ?
– diegoveloper
Nov 11 at 2:37
@diegoveloper oh I see, that’s because I want the user to be able to go back to the homepage by tapping the first item in the bottomNavigationBar()
– Garrett
Nov 11 at 2:38
if you put these options : final _pageOptions = [ CatPage(), SearchPage(), ]; does it works ? if not , what do you have inside CatPage and SearchPage?
– diegoveloper
Nov 11 at 2:40
|
show 5 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to use the BottomNavigationBar
in Flutter, however it is giving me a weird error that seem to have no reference to my code and I am not able to find this error anywhere online. In fact every tutorial, page, or question I can find says to do it this way.
Here is my code from home.dart
:
... Imports ...
class HomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return HomePageState();
}
}
class HomePageState extends State<HomePage> {
int _selectedTab = 0;
final _pageOptions = [
HomePage(),
CatPage(),
SearchPage(),
];
void _onItemTapped(int index) {
setState(() {
_selectedTab = index;
});
print(index);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Loopt In'),
),
body: _pageOptions[_selectedTab],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedTab,
onTap: _onItemTapped,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.category),
title: Text('Categories'),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
title: Text('Search'),
),
],
),
);
}
}
Interestingly enough when I change the _pageOptions
array to have a Text()
widgets instead of widgets that I made it work fine, but I don't know why and need it to work with my widgets obviously.
Here's the error I'm getting:
[VERBOSE-2:shell.cc(181)] Dart Error: Unhandled exception:
'package:flutter/src/widgets/framework.dart': Failed assertion: line 2257 pos 20: '_debugCurrentBuildTarget == context': is not true.
#0 _AssertionError._doThrowNew (dart:core/runtime/liberrors_patch.dart:40:39)
#1 _AssertionError._throwNew (dart:core/runtime/liberrors_patch.dart:36:5)
#2 BuildOwner.buildScope.<anonymous closure> (package:flutter/src/widgets/framework.dart:2257:20)
#3 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2261:12)
#4 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:817:13)
#5 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:709:7)
#6 runApp (package:flutter/src/widgets/binding.dart:748:7)
#7 main (file:///Users/garrettlove/Documents/learn/Flutter/loopt_in/lib/main.d<…>
dart flutter
I am trying to use the BottomNavigationBar
in Flutter, however it is giving me a weird error that seem to have no reference to my code and I am not able to find this error anywhere online. In fact every tutorial, page, or question I can find says to do it this way.
Here is my code from home.dart
:
... Imports ...
class HomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return HomePageState();
}
}
class HomePageState extends State<HomePage> {
int _selectedTab = 0;
final _pageOptions = [
HomePage(),
CatPage(),
SearchPage(),
];
void _onItemTapped(int index) {
setState(() {
_selectedTab = index;
});
print(index);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Loopt In'),
),
body: _pageOptions[_selectedTab],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedTab,
onTap: _onItemTapped,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.category),
title: Text('Categories'),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
title: Text('Search'),
),
],
),
);
}
}
Interestingly enough when I change the _pageOptions
array to have a Text()
widgets instead of widgets that I made it work fine, but I don't know why and need it to work with my widgets obviously.
Here's the error I'm getting:
[VERBOSE-2:shell.cc(181)] Dart Error: Unhandled exception:
'package:flutter/src/widgets/framework.dart': Failed assertion: line 2257 pos 20: '_debugCurrentBuildTarget == context': is not true.
#0 _AssertionError._doThrowNew (dart:core/runtime/liberrors_patch.dart:40:39)
#1 _AssertionError._throwNew (dart:core/runtime/liberrors_patch.dart:36:5)
#2 BuildOwner.buildScope.<anonymous closure> (package:flutter/src/widgets/framework.dart:2257:20)
#3 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2261:12)
#4 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:817:13)
#5 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:709:7)
#6 runApp (package:flutter/src/widgets/binding.dart:748:7)
#7 main (file:///Users/garrettlove/Documents/learn/Flutter/loopt_in/lib/main.d<…>
dart flutter
dart flutter
edited Nov 11 at 6:25
CopsOnRoad
2,26511017
2,26511017
asked Nov 11 at 2:03
Garrett
402318
402318
do you have HomePage inside HomePage ? HomePage(), CatPage(), SearchPage(),
– diegoveloper
Nov 11 at 2:32
@diegoveloper I'm not really sure what you mean. What i posted is my entire HomePage. CatPage() and SearchPage() currently only return Text() widgets
– Garrett
Nov 11 at 2:35
I mean, your main widget is : HomePage , then in your _pageOptions var I see [HomePage(), CatPage(), SearchPage()] , why are you calling HomePage again inside HomePage ?
– diegoveloper
Nov 11 at 2:37
@diegoveloper oh I see, that’s because I want the user to be able to go back to the homepage by tapping the first item in the bottomNavigationBar()
– Garrett
Nov 11 at 2:38
if you put these options : final _pageOptions = [ CatPage(), SearchPage(), ]; does it works ? if not , what do you have inside CatPage and SearchPage?
– diegoveloper
Nov 11 at 2:40
|
show 5 more comments
do you have HomePage inside HomePage ? HomePage(), CatPage(), SearchPage(),
– diegoveloper
Nov 11 at 2:32
@diegoveloper I'm not really sure what you mean. What i posted is my entire HomePage. CatPage() and SearchPage() currently only return Text() widgets
– Garrett
Nov 11 at 2:35
I mean, your main widget is : HomePage , then in your _pageOptions var I see [HomePage(), CatPage(), SearchPage()] , why are you calling HomePage again inside HomePage ?
– diegoveloper
Nov 11 at 2:37
@diegoveloper oh I see, that’s because I want the user to be able to go back to the homepage by tapping the first item in the bottomNavigationBar()
– Garrett
Nov 11 at 2:38
if you put these options : final _pageOptions = [ CatPage(), SearchPage(), ]; does it works ? if not , what do you have inside CatPage and SearchPage?
– diegoveloper
Nov 11 at 2:40
do you have HomePage inside HomePage ? HomePage(), CatPage(), SearchPage(),
– diegoveloper
Nov 11 at 2:32
do you have HomePage inside HomePage ? HomePage(), CatPage(), SearchPage(),
– diegoveloper
Nov 11 at 2:32
@diegoveloper I'm not really sure what you mean. What i posted is my entire HomePage. CatPage() and SearchPage() currently only return Text() widgets
– Garrett
Nov 11 at 2:35
@diegoveloper I'm not really sure what you mean. What i posted is my entire HomePage. CatPage() and SearchPage() currently only return Text() widgets
– Garrett
Nov 11 at 2:35
I mean, your main widget is : HomePage , then in your _pageOptions var I see [HomePage(), CatPage(), SearchPage()] , why are you calling HomePage again inside HomePage ?
– diegoveloper
Nov 11 at 2:37
I mean, your main widget is : HomePage , then in your _pageOptions var I see [HomePage(), CatPage(), SearchPage()] , why are you calling HomePage again inside HomePage ?
– diegoveloper
Nov 11 at 2:37
@diegoveloper oh I see, that’s because I want the user to be able to go back to the homepage by tapping the first item in the bottomNavigationBar()
– Garrett
Nov 11 at 2:38
@diegoveloper oh I see, that’s because I want the user to be able to go back to the homepage by tapping the first item in the bottomNavigationBar()
– Garrett
Nov 11 at 2:38
if you put these options : final _pageOptions = [ CatPage(), SearchPage(), ]; does it works ? if not , what do you have inside CatPage and SearchPage?
– diegoveloper
Nov 11 at 2:40
if you put these options : final _pageOptions = [ CatPage(), SearchPage(), ]; does it works ? if not , what do you have inside CatPage and SearchPage?
– diegoveloper
Nov 11 at 2:40
|
show 5 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245221%2fflutter-bottom-navigation-bar-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
do you have HomePage inside HomePage ? HomePage(), CatPage(), SearchPage(),
– diegoveloper
Nov 11 at 2:32
@diegoveloper I'm not really sure what you mean. What i posted is my entire HomePage. CatPage() and SearchPage() currently only return Text() widgets
– Garrett
Nov 11 at 2:35
I mean, your main widget is : HomePage , then in your _pageOptions var I see [HomePage(), CatPage(), SearchPage()] , why are you calling HomePage again inside HomePage ?
– diegoveloper
Nov 11 at 2:37
@diegoveloper oh I see, that’s because I want the user to be able to go back to the homepage by tapping the first item in the bottomNavigationBar()
– Garrett
Nov 11 at 2:38
if you put these options : final _pageOptions = [ CatPage(), SearchPage(), ]; does it works ? if not , what do you have inside CatPage and SearchPage?
– diegoveloper
Nov 11 at 2:40