-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Navbar hides when pushing a new screen from floatingActionButton. #46
Comments
I have actually found another issue with the floating action button. Flutter throws a multiple heroes exception. The Stack════════ Exception caught by scheduler library ═════════════════════════════════ The following assertion was thrown during a scheduler callback: There are multiple heroes that share the same tag within a subtree.Within each subtree for which heroes are to be animated (i.e. a PageRoute subtree), each Hero must have a unique non-null tag. |
The Regarding the multiple heroes: Do you know when exactly it happens? |
I actually managed to fix the multiple heroes exception. That was being cause by another package which I ultimately removed and implemented myself. As for the navbar solution, what is exactly |
It is just a variable that holds the |
Sorry I'm having a hard time comprehending this. Like what exactly is Could you please provide a code snippet? |
This should work class CustomWidgetExample extends StatefulWidget {
CustomWidgetExample({Key key}) : super(key: key);
@override
_CustomWidgetExampleState createState() => _CustomWidgetExampleState();
}
class _CustomWidgetExampleState extends State<CustomWidgetExample> {
PersistentTabController _controller;
BuildContext currentTabContext;
@override
void initState() {
super.initState();
_controller = PersistentTabController(initialIndex: 0);
}
List<Widget> _buildScreens() {
return [
MainScreen(),
MainScreen(),
MainScreen(),
MainScreen(),
MainScreen(),
];
}
List<PersistentBottomNavBarItem> _navBarsItems() {
return [
PersistentBottomNavBarItem(
icon: Icon(Icons.home),
title: "Home",
activeColorPrimary: Colors.blue,
inactiveColorPrimary: Colors.grey,
),
PersistentBottomNavBarItem(
icon: Icon(Icons.search),
title: ("Search"),
activeColorPrimary: Colors.teal,
inactiveColorPrimary: Colors.grey,
),
PersistentBottomNavBarItem(
icon: Icon(Icons.add),
title: ("Add"),
activeColorPrimary: Colors.deepOrange,
inactiveColorPrimary: Colors.grey,
),
PersistentBottomNavBarItem(
icon: Icon(Icons.settings),
title: ("Settings"),
activeColorPrimary: Colors.indigo,
inactiveColorPrimary: Colors.grey,
),
PersistentBottomNavBarItem(
icon: Icon(Icons.settings),
title: ("Settings"),
activeColorPrimary: Colors.indigo,
inactiveColorPrimary: Colors.grey,
),
];
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Navigation Bar Demo')),
body: PersistentTabView.custom(
context,
controller: _controller,
screens: _buildScreens(),
items: _navBarsItems(),
itemCount: 5,
customWidget: (navBarEssentials) => CustomNavBarWidget(
items: _navBarsItems(),
onItemSelected: (index) {
setState(() {
navBarEssentials.onItemSelected(index);
});
},
selectedIndex: _controller.index,
),
selectedTabScreenContext: (context) => currentTabContext = context,
floatingActionButton: FloatingActionButton(
onPressed: () {
pushNewScreen(
currentTabContext,
screen: Container(
color: Colors.red,
),
withNavBar: true,
);
},
),
),
);
}
}
class CustomNavBarWidget extends StatelessWidget {
final int selectedIndex;
final List<PersistentBottomNavBarItem> items;
final ValueChanged<int> onItemSelected;
CustomNavBarWidget({
Key key,
this.selectedIndex,
@required this.items,
this.onItemSelected,
});
Widget _buildItem(PersistentBottomNavBarItem item, bool isSelected) {
return Container(
alignment: Alignment.center,
height: kBottomNavigationBarHeight,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Flexible(
child: IconTheme(
data: IconThemeData(
size: 26.0,
color: isSelected
? (item.activeColorSecondary == null
? item.activeColorPrimary
: item.activeColorSecondary)
: item.inactiveColorPrimary == null
? item.activeColorPrimary
: item.inactiveColorPrimary),
child: isSelected ? item.icon : item.inactiveIcon ?? item.icon,
),
),
Padding(
padding: const EdgeInsets.only(top: 5.0),
child: Material(
type: MaterialType.transparency,
child: FittedBox(
child: Text(
item.title,
style: TextStyle(
color: isSelected
? (item.activeColorSecondary == null
? item.activeColorPrimary
: item.activeColorSecondary)
: item.inactiveColorPrimary,
fontWeight: FontWeight.w400,
fontSize: 12.0),
),
),
),
),
],
),
);
}
@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: Container(
width: double.infinity,
height: kBottomNavigationBarHeight,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: items.map((item) {
int index = items.indexOf(item);
return Expanded(
child: InkWell(
onTap: () {
this.onItemSelected(index);
},
child: _buildItem(item, selectedIndex == index),
),
);
}).toList(),
),
),
);
}
} |
Thank you. It works as intended now. |
So basically I want a floating action button to be present on all screen. For this I am implementing it like so:
The issue is that when this new screen is pushed, the navbar becomes hidden even though the
withNavBar: true
property.Is this by design or is this fixable?
The text was updated successfully, but these errors were encountered: