The named parameter 'title' isn't defined. problem in flutter - 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

Related

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

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

BottomNavigationBar // Controlling Height with SizedBox leads to overflow

The goal:
Instead of using the hard coded height for the BottomNavigationBar, I want to size it as a fraction of the screen height.
My approach so far: I figured out that I can wrap the BottomNavigationBar in a SizedBox and control the height that way. Code at the botom.
The problem: I get overflows with the BottomNavigationBarItems on various devices.
I tried scaling the icons using the height of the SizedBox, but I need to make the items pretty small to avoid the overflow so that is not an option.
The code:
final bottomNavHeight = MediaQuery.of(context).size.heigth * 0.085;
bottomNavigationBar: SizedBox(
height: bottomNavHeight,
child: BottomNavigationBar(
onTap: _selectPage,
iconSize: bottomNavHeight * 0.45,
showSelectedLabels: false,
showUnselectedLabels: false,
currentIndex: _selectedPageIndex,
type: BottomNavigationBarType.fixed,
items: [
//home
BottomNavigationBarItem(
icon: Icon(Icons.home, color: _customColorScheme['Icon 1']),
activeIcon:
Icon(Icons.home, color: _customColorScheme['Icon 2']),
label: '',
),
//favorite
BottomNavigationBarItem(
icon:
Icon(Icons.favorite, color: _customColorScheme['Icon 1']),
activeIcon:
Icon(Icons.favorite, color: _customColorScheme['Icon 2']),
label: '',
),
//loockback
BottomNavigationBarItem(
icon: Icon(Icons.bar_chart,
color: _customColorScheme['Icon 1']),
activeIcon: Icon(Icons.bar_chart,
color: _customColorScheme['Icon 2']),
label: '',
),
//info & support
BottomNavigationBarItem(
icon: Icon(Icons.info, color: _customColorScheme['Icon 1']),
activeIcon:
Icon(Icons.info, color: _customColorScheme['Icon 2']),
label: '',
),
you can use like this like css break
final bottomNavHeight = getMyheight(context);
getMyheight(BuildContext context) {
var mheight = MediaQuery.of(context).size.height;
if (mheight < 300)
return mheight * 0.80;
else if (mheight < 400)
return mheight * 0.2;
else if (mheight < 500)
return mheight * 0.2;
else if (mheight < 600)
return mheight * 0.2;
else if (mheight < 800)
return mheight * 0.3;
else
return mheight * 0.085;
}
TIP
For Discrete jump i used windows run
NB: some packages dependent on platform so may exception so for ui testing it best discrete screen.
On Windows, desktop support is enabled on Flutter 2.10 or higher. On
macOS and Linux, desktop support is disabled by default in the stable
channel. You can manually enable it with one of these commands,
depending on which platform you are running:
flutter config --enable-macos-desktop
flutter config --enable-linux-desktop
flutter config --enable-windows-desktop
This package use to test different screen sizedevicepreview
device_preview: ^1.0.0
The bottom-overflow starts around <704. BottomNavigationBarItem's is not getting enough space.
You can remove SizedBox and just start with BottomNavigationBar, it will solve the issue.
bottomNavigationBar: BottomNavigationBar(....)

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

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