I have a BottomNavigationBar() in my app however after I updated to Flutter 1.22 the title parameter is deprecated. As the new label only takes a String input I cannot pass the Text() widget to pass a custom TextStyle. How do I achieve this now with the new update?
BottomNavigationBarItem(icon: Icon(Icons.notifications), label: 'tickets'),
BottomNavigationBarItem(icon: Icon(CustomIcons.calendar), label: 'calendar'),
BottomNavigationBarItem(icon: Icon(CustomIcons.home), label: 'home'),
BottomNavigationBarItem(icon: Icon(CustomIcons.podcasts), label: 'microphone'),
BottomNavigationBarItem(icon: Icon(CustomIcons.search), label: 'search')
BottomNavigationBar(
selectedLabelStyle: TextStyle(),//your text style
unselectedLabelStyle: TextStyle(),// your text style
items: [
BottomNavigationBarItem(icon: Icon(Icons.notifications), label: 'tickets'),
BottomNavigationBarItem(icon: Icon(CustomIcons.calendar), label: 'calendar'),
BottomNavigationBarItem(icon: Icon(CustomIcons.home), label: 'home'),
BottomNavigationBarItem(icon: Icon(CustomIcons.podcasts), label:
'microphone'),
BottomNavigationBarItem(icon: Icon(CustomIcons.search), label: 'search'),
]
)
Related
When I am used BottomNavigationBarItem, I can't showing my navigation icons.
I am trying this code:
import 'package:flutter/material.dart';
import 'package:task_manager/style/style.dart';
BottomNavigationBar AppBottomNav(currentIndex, OnItemTapped) {
return BottomNavigationBar(
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.list_alt),
label: "New",
),
BottomNavigationBarItem(
icon: Icon(Icons.access_time_rounded),
label: "Progress",
),
BottomNavigationBarItem(
icon: Icon(Icons.check_circle_outlined),
label: "Completed",
),
BottomNavigationBarItem(
icon: Icon(Icons.cancel),
label: "Canceled",
),
],
selectedItemColor: colorGreen,
unselectedItemColor: colorLightGray,
currentIndex: currentIndex,
showSelectedLabels: true,
showUnselectedLabels: true,
onTap: OnItemTapped,
type: BottomNavigationBarType.shifting,
);
}
You need to set uses-material-design: true in pubspec.yaml
Like Alejandro Cumpa said, you need to add uses-material-design: true in your pubspec.yaml.
You need to add this to the bottom:
name: …
description: …
publish_to: …
version: …
environment:
…
dependencies:
…
dev_dependencies:
…
flutter:
…
uses-material-design: true
I tried to Run flutter and i got this error: Another exception was thrown: Assertion failed:
file:///home/moi/snap/flutter/common/flutter/packages/flutter/lib/src/material/bottom_navigation_bar.dart:189:9
You need to provide label on your BottomNavigationBarItem.
You can just empty string like
BottomNavigationBarItem(icon: Icon(Icons.abc), label: ""),
If you like to hide labels, do like this
bottomNavigationBar: BottomNavigationBar(
showSelectedLabels: false,// this
showUnselectedLabels: false,// this
items: [
BottomNavigationBarItem(icon: Icon(Icons.abc), label: ""),
BottomNavigationBarItem(icon: Icon(Icons.abc), label: ""),
],
),
new BottomNavigationBarItem(
icon: new Icon(Icons.home, color: (_page == 0) ?Color.fromRGBO(79, 119,45,1) : Color.fromRGBO(236, 243,158,1)),
title: new Container(height: 0.0),
It will be label as title is deprecated for that.
Follow this link : https://docs.flutter.dev/release/breaking-changes/bottom-navigation-title-to-label
I'm getting this issue after after updating from old version (Title) to Label in the bottom nav bar. Here's a sample of the code:
BottomNavigationBarItem(
icon: Icon(iconname.shop),
label: Text(
'Store',
style: tabLinkStyle,
)),
label is accepting String?, not a widget, so your code should be as following:
BottomNavigationBarItem(
icon: Icon(conname.shop),
label: 'Store',
),
I'm using Auto_Route for routing in my application and AutoTabsScaffold makes it easier. But by default, the user is navigated to the first page in the bottom navigation bar but I want it to be navigated to third page by default. How can I do that?
Here's a snippet of the code:
AutoTabsScaffold(
routes: [
A(),
B(),
C(),
D(),
E(),
],
bottomNavigationBuilder: (_, tabsRouter) {
return BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: Colors.black,
selectedItemColor: const Color(0XFFEAF8FF),
unselectedItemColor: Colors.grey,
currentIndex: tabsRouter.activeIndex,
onTap: tabsRouter.setActiveIndex,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.groups_outlined), label: ""),
BottomNavigationBarItem(icon: Icon(Icons.search), label: ""),
BottomNavigationBarItem(
icon: Icon(Icons.catching_pokemon), label: ""),
BottomNavigationBarItem(
icon: Icon(Icons.library_add_check_outlined), label: ""),
BottomNavigationBarItem(
icon: Icon(Icons.person_outline), label: ""),
],
);
I want the user to land on C() and not A(). How can I do that? Thanks in advance.
Had the same issue.
I use auto_route package in my project.
We can see that current index depend on tabsRouter.activeIndex property.
So, I just added to the preferred route initial: true, property.
Like this:
CustomRoute(
path: '/',
page: MainScreen,
name: 'MainScreenRoute',
guards: [AuthGuard],
transitionsBuilder: TransitionsBuilders.fadeIn,
children: [
AutoRoute(
path: 'wallet',
page: WalletScreen,
),
AutoRoute(
path: 'trades',
page: TradesScreen,
),
AutoRoute(
path: 'market',
initial: true,
page: MarketScreen,
),