Flutter FloatingActionButton and IconButton - flutter

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

Related

How to change what the back button does in dart

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

How to make a button in Flutter have the same shape as its icon?

I am trying to create a backspace button (using an ElevatedButton()). I don't want the button to be circular, but instead have the same shape as the icon. Also, when tapping the button, I want the splash effect to be the same size and shape as the button.
I've attached a reference image below of the shape I'm trying to replicate.
Extra challenge: I'm also trying to set the fill color of the button to be black and the color of the button to be grey (like the example).
You can use the IconButton() widget instead of ElevtaedButton() as well as defining the splashRadius to change the size of the splash effect:
IconButton(
splashRadius: 1, // Set the Size of the splash area
color: Colors.grey,
icon: Icon(Icons.backspace),
onPressed: () {},
),
Result:
Or, if you want to use ElevatedButton(), use the .icon constructor:
ElevatedButton.icon(
style: ElevatedButton.styleFrom(primary: Colors.grey.shade300),
label: Text('Hello World'),
icon: Icon(
Icons.backspace,
color: Colors.grey,
),
onPressed: () {},
)
Result:
There are many default icons in class Icons are not good-looking for your app. You can use some design platform, such as Figma, then download it as svg. Then the code could be:
InkWell(
onTap: () {},
child: SvgPicture.asset(path_to_svg_icon)
)
This way, you can edit color, shape, style... for your icon. Good luck!

Different icon for appBar back button in the whole app

When navigating between pages in flutter, if the second page has an AppBar, by default the AppBar comes with an IconButton to go back to the previous page. Is there a way to set a custom icon for that IconButton that is different than the one provided by default by Flutter and will be applied to every other page? Kind of like a custom AppBarTheme?
You can remove the BackButton and handling it by yourself, using:
AppBar(
automaticallyImplyLeading: false,
leading: Navigator.canPop(context)
? IconButton(
icon: Icon(
Icons.arrow_back,
color: Colors.black,
size: 47,
),
onPressed: () => Navigator.of(context).pop(),
)
: null,
);

ListTile covers button animation

Just noticed that ListTile cover button animation when wrapped inside a container with background color set to anything but transparent. Wrapping ListTile in a container with set color is the only way I know to change background color of ListTile. Is there any other way to change background color of the ListTile without loosing button animation?
Container(
color: Colors.green,
child: ListTile(
title: Text('Test'),
trailing: IconButton(
icon: Icon(Icons.add),
onPressed: () {},
),
),
)
OUTPUT
This is because of the way InkWell works (Some buttons, like the IconButton, use InkWell or InkResponse as their parent). You can read about it more on this github issue page.
In order to make that ripple effect to display on top of the decorated Container (the green one in your code) - it needs a Material widget above the Container in the widget display tree.
So you should edit the code and add a Material widget with transparency in your Container, so the widget display tree will look like Container -> Material -> Ink.
Container(
color: Colors.green,
child: Material(
type: MaterialType.transparency,
child: ListTile(
title: Text('Test'),
trailing: IconButton(
icon: Icon(Icons.add),
onPressed: () {},
),
),
),
),

Long hold on back arrow of action bar in flutter shows a "Back" toast, how to remove that?

How to remove the toast displayed on the Action bar in a flutter on Long hold on back arrow.
In your appBar you can replace the leading parameter by what you want.
Try replacing it with :
AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.of(context).pop();
},
),
),
It should remove the tooltip. If you want to customize it, see the tooltip parameter of IconButton
Use an IconButton as leading widget of your AppBar like,
Scaffold(
appBar: AppBar(
leading: IconButton(
onPressed: () {
Navigator.of(context).pop();
},
icon: Icon(Icons.arrow_back),
// tooltip: 'Back', // this cause the overlay
),
),
);