The argument type 'Text' can't be assigned to the parameter type 'String' - flutter

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',
),

Related

i tried to Run flutter i got this :Assertion failed:

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: ""),
],
),

The named parameter 'title' isn't defined. problem in flutter

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

How to land the user on a different page while using AutoTabsScaffold and BottomNavigationBar?

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,
),

flutter 1.23.0-18.1pre BottomNavigationBar deprecated 'title' use 'label'

The title part is giving an error telling me that i should use label instead.
The Error is:
info: 'title' is deprecated and shouldn't be used. Use "label" instead, as it allows for an improved text-scaling experience. This feature was deprecated after v1.19.0.. (deprecated_member_use at lib/Screens/hostHomePage.dart:49)
Hopefully someone can help me out?
BottomNavigationBarItem _buildNavigationItem(
int index, IconData iconData, String text) {
return BottomNavigationBarItem(
icon: Icon(
iconData,
color: AppConstants.nonSelectedIconColor,
),
activeIcon: Icon(
iconData,
color: AppConstants.selectedIconColor,
),
title: Text(
text,
style: TextStyle(
color: _selectedIndex == index
? AppConstants.selectedIconColor
: AppConstants.nonSelectedIconColor,
),
),
);
}
As I see in the documents the things you are mentioning are correct and to have it working you must use label and pass a string to it. And remove the title parameter wherein you pass a widget.
BottomNavigationBarItem _buildNavigationItem(
int index, IconData iconData, String text) {
return BottomNavigationBarItem(
icon: Icon(
iconData,
color: AppConstants.nonSelectedIconColor,
),
activeIcon: Icon(
iconData,
color: AppConstants.selectedIconColor,
),
label: text
);
}
This code should work out for you instead of the one you are writing right now. :-).
link to the newer documentation

Flutter app - Problems Lifting State...Suggestions?

I'm working on a Flutter app and trying to make my bottom navigator bar more universal. As part of that, I've moved it to its own file and now need to simply lift state up to the parent class in order to highlight the selected icon. I call it like so from the parent:
bottomNavigationBar: buildBottomNavBar(
selectedIndex: selectedIndex,
redrawDisplay: redrawDisplay,
context: context,
),
And the bottomNaviBar is built like so:
return BottomNavigationBar(
currentIndex: selectedIndex,
onTap: (int index) {
selectedIndex = index;
redrawDisplay(selectedIndex);
onBottomMenuTap(index, appProject.picsSelectable, context);
},
elevation: 5.0,
iconSize: 30.0,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.note_add),
label: 'Add Metadata',
),
BottomNavigationBarItem(
icon: Icon(Icons.share),
label: 'Share Pics',
),
BottomNavigationBarItem(
icon: Icon(Icons.delete),
label: 'Delete Pics',
),
],
);
The 'redrawDisplay' function is simply a function in the parent class that sets state, like so:
void redrawDisplay({int selectedIndex}) {
setState(() {
this.selectedIndex = selectedIndex ?? 0;
});
}
I swear this was working a few days ago, but now I'm getting the following exception:
════════ Exception caught by gesture ═════════════════════════════════════════════
Closure call with mismatched arguments: function '_SearchScreenState.redrawDisplay'
Receiver: Closure: ({int selectedIndex}) => dynamic from Function 'redrawDisplay':.
Tried calling: _SearchScreenState.redrawDisplay(0)
Found: _SearchScreenState.redrawDisplay({int selectedIndex}) => dynamic
═══════════════════════════════════════════════════════════════════════
Obviously something has changed in my code, but I have been staring at this for hours and haven't cracked it yet. Anybody have some insight into what I've screwed up?
Thanks in advance.