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

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

Related

how to add delete option in dropdown in flutter

I'm working in small project. For Login, I need to save URL in shared preferences so that next time user can select it in dropdown. I need to keep delete option in that dropdown to delete old URL. How to do?
code:
if (getALLURL.isNotEmpty) ...[
DropdownButton<String>(
value: baseurl.isNotEmpty ? baseurl : null,
borderRadius: BorderRadius.circular(2.0),
underline: SizedBox(),
focusColor: AppColors().linenDark,
elevation: 1,
enableFeedback: true,
isExpanded: true,
style: GoogleFonts.montserrat(
fontSize: AppSizes().paraLarge16,
color: AppColors().linenDark,
fontWeight: FontWeight.w400),
icon: Icon(
Icons.keyboard_arrow_down_rounded,
color: AppColors().linenMedium,
),
items: getALLURL.map((String item) {
return DropdownMenuItem<String>(
child: Text(item),
value: item,
);
}).toList(),
onChanged: (value) async {
setState(() {
baseurl = value!;
print(baseurl);
});
await Prefs().setBaseURLLogin(baseurl);
},
hint: Text("Select item"),
),
//IconButton(onPressed: onDelete, icon: Icon(Icons.delete))
],
Now I'm only used text in menuitems, how to add delete in it. Can I delete particular value in shared preferences
Can I delete particular value in shared preferences
Yes, you can write new value over the old one with same key.
Now I'm only used text in menuitems, how to add delete in it
i don't think it could support that directly . Even if it , i recommended you to use instead way for delete option such as any position of the screen.

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 use image asset as Icon in Flutter?

I want to use image asset for AnimatedIconItem in big_button_example.dart file in animated_icon_button flutter library. You can find the library on pub.dev. SimpleIcons is used for Icon. Original code is :
AnimatedIconItem(
icon: Icon(SimpleIcons.nasa, color: color),
backgroundColor: Colors.white,
),
I want to use image asset for icon variable. I tried these :
icon: ImageIcon(
AssetImage("images/icon.png"),
color: Color(0xFF3A5A98),
),
icon: Image.asset('assets/icon.png'),
icon: IconButton(
icon: Image.asset('assets/icon.png'),
),
But always I got error like The argument type 'ImageIcon' can't be assigned to the parameter type 'Icon'. How can I use image for Icon?
Try this:
class Menu {
const Menu({this.icon, this.title});
final ImageIcon icon;
final String title;
}
const List<Menu> menus = const <Menu>[
const Menu(
title: 'menu_icon_1',
icon:ImageIcon(
AssetImage('assets/menu/11.png')
),
),
];

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.

Little help here putting logic on icons

I have this list
final List<String> entries = <String>['Life', 'Car', 'Car'];
then i try to generate 3 widgets each one with an icon depending on the values that have the array i tried in this way
children:<Widget>[
Icon(
entries=='Life'? Icons.favorite_border:Icons.directions_car,
color: Colors.white,
textDirection: TextDirection.ltr,
size:50,
),
but all widgets get the favorite_border icon instead of mixing between directions_car and favorite_border.
entries is a list, you can't compare it with a String. Use map in entries list to generate it to a list of Icon.
List icons = [Icons.favorite_border, Icons.directions_car,...]
entries.map<Icon>((String entry) {
return Icon(
icons[entries.indexOf(entry)],
color: Colors.white,
textDirection: TextDirection.ltr,
size:50,
)
});
You can try to verify each item in your array. Like this below:
children: <Widget>[
...entries.map(
(icon) => Icon(
icon == 'Life' ? Icons.favorite_border : Icons.directions_car,
),
)
],