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<…>









share|improve this question
























  • 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















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<…>









share|improve this question
























  • 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













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<…>









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python