I use vscode + flutter plugin. Why 'title' in BottomNavigationBarItem or 'RaisedButton' are crossed out by flutter?
BottomNavigationBarItem(icon: Icon(Icons.map_outlined), title: Text("help"))
vscode screen
They are being deprecated, which means that the Flutter Team now recommends that you don't use them anymore, and gives you some alternatives.
For BottomNavigationBarItem's title property, use the label property instead:
BottomNavigationBarItem(icon: Icon(Icons.map_outlined), label: "help")
and for the RaisedButton, now use ElevatedButton:
ElevatedButton(onPressed: () => null, child: Text("Click Me"));
Also, with the ElevatedButton styling has become a little different.
To style an ElevatedButton use:
ElevatedButton(
onPressed: () => null,
child: Text("Click Me"),
style: ElevatedButton.styleFrom(primary: Colors.green, etc....)
);
Related
How can I change the function of the back button in dart flutter
I really didn't try anything because tbh, i didn't find what to try
You need simply to override the leading property in the AppBar with a new IconButton, then set your specific method:
AppBar(
leading: IconButton(
onPressed: () {
print("clicked");
},
icon: Icon(Icons.abc),
),
),
I created a simple bottom navigation bar, (my code below)...
bottomNavigationBar: BottomNavigationBar(
backgroundColor: COLOR_WHITE,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.account_circle_rounded),
label: 'Profile',
),
BottomNavigationBarItem(
label: 'something', icon: Icon(Icons.star)),
],
)
...but then I really wanted to click on the icons, so I tried adding an Icon Button for its onPressed() method.
bottomNavigationBar: BottomNavigationBar(
backgroundColor: COLOR_WHITE,
items: [
BottomNavigationBarItem(
icon: IconButton(
icon: const Icon(Icons.account_circle_rounded),
onPressed: () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => ProfileScreen(userID :widget.userID)),
);
},
),
label: "Profile"
),
BottomNavigationBarItem(
label: 'something', icon: Icon(Icons.star)),
],
),
It gets all ugly, and I wanted the paddings and size all around to remain the same, but since I didn't add code to change those features, I don't get why it happened in the first place. Can someone help me solve it? Thanks!!
BottomNavigationBar has an onTap method you can use to trigger your callbacks so you don't need an IconButton. onTap gives you the index of the item tapped so you can map it to the appropriate page. You can also update the currentIndex property on the BottomNavigatorBar to highlight the appropriate item.
See this documentation for BottomNavigationBar for a good example: https://api.flutter.dev/flutter/material/BottomNavigationBar-class.html
the mistake you have made was in the first BottomNavigationBarItem you have IconButton Widget and in second Icon widget... both having different styles by default(flutter developers gave default values for padding size etc)... so below code will work. i implemented locally and checked as well..
BottomNavigationBar(
backgroundColor: Colors.white,
items: [
BottomNavigationBarItem(
icon: IconButton(
icon: const Icon(Icons.account_circle_rounded),
onPressed: () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) =>
ProfileScreen(userID:widget.userID)),
);
},[enter image description here][1]
),
label: "Profile"
),
BottomNavigationBarItem(
label: 'something', icon: IconButton(
icon: const Icon(Icons.star),
onPressed: () {
},
),),
],
)
enter image description here
I can't seem to find a parameter that lets the widgets TextButton.icon and ElevatedButton.icon place the label first then the icon. Is there a way or do I have to make a custom widget for this?
Example:
ElevatedButton.icon(
onPressed: () { /* code */ },
icon: Icon(Icons.arrow_forward),
label: Text('Some text'),
)
Both icon & label accepts a Widget. So you could do this:
ElevatedButton.icon(
icon: Text('A'),
label: Icon(Icons.add),
onPressed: () {},
),
I have made a flatbutton icon, but it seems this is depreciated in the current flutter version. I have tried to upgrade it to a text button, but it does not show the text next to the icon.
This is the original code that has to be adapted to become a text button. Should I have to define a class or function to make it so?
Row(
children: [
FlatButton.icon(
onPressed: () => print('Live'),
icon: const Icon(
icons.videocam,
color: Colors.red,
),
label: Text('Live'),
),
],
)
Thx! :)
you can use TextButton.icon() widget. here an example:
TextButton.icon(
onPressed: () => print('Live'),
icon: Icon(Icons.videocam_rounded),
label: Text('Live'),
),
and here the result:
You can use an IconButton widget:
Row(
children: [
IconButton(
onPressed: () => print('Live'),
icon: const Icon(icons.videocam, color: Colors.red),
),
Text('Live'),
]
)
How can I create a FloatingActionButton like in the image?
I tried using FloatingActionButton, but it looks like a whole button with a circle.
I need something like an IconButton as shown in the image.
IconButton will actually deliver the result you are aiming for!
A FloatingActionButton, by guidelines, will always deliver the design you find on your "View in Your Room" titled button.
IconButton(
icon: Icon(Icons.back),
onPressed...
)
You need to use IconButton as below
// Icon Button
new IconButton(
icon: new Icon(Icons.favorite),
tooltip: 'Facorite icon',
color: Colors.blue, //set color which you want
onPressed: () {
// Do your work
},
),
For this, you can use actions ** property of appbar to put icons on the right side of title and **leading property to put a leading icon.
appbar: new AppBar(
leading: new Icon(Icons.search),
actions: <Widget>[
new Icon(Icons.search),
new Icon(Icons.search),
],
title: new Text("title"),
)
I suggest using an Icon inside a GestureDetector widget. This will give you the result you want, but also getting rid of the unnecessary padding around an IconButton.
GestureDetector(
onTap: () {},
child: Icon(Icons.arrow_back, color: Colors.black)
)