I'm currently trying to add the text ('Filter'), underneath an icon inside of the actions field within an AppBar.
Without any text being added underneath it. the action aligned exactly with the text and hamburger menu icon
Example:
There are two issues I'm having:
When I add text, the filter icon moves up a little, I want the icon to be the same spot but text added understand.
I'm getting an overflow issue
How can I fix this?
Thanks!
_appbarActions = [
Column(
children: [
IconButton(icon: const Icon(Icons.filter_alt_outlined), onPressed: () {}),
Text('Filter'),
],
)
];
Try the below snippet code:
To remove the space between IconButton and Text use Icon only;
For the overflow error you can manage the icon size with text fontSize (styles);
For events wrap the column by InkWell widget
Container(
margin: const EdgeInsets.only(right: 8.0),
child: InkWell(
onTap: () {},
child: Stack(
children: [
Center(
child: Icon(Icons.filter_alt_outlined),
),
Positioned(
child: Text(
'Filter',
style: TextStyle(fontSize: 10.0),
),
bottom: 5,
),
],
),
),
)
Is there anyway that I can position text in the extended floating action button.
For example I want to position text at the right corner of the button.
How can I do this ?
Thank you for your help.
The FloatingActionButton in the Scaffold accepts a widget. So you can do something like this:
floatingActionButton: Stack(
children: [
FloatingActionButton.extended(
// label cannot be null, but it's a widget
// so it can be an empty container or something else
label: Text("button"),
icon: Icon(Icons.add),
onPressed: () {},
),
Positioned(right: 0.0, top: 0.0, child: Text("text")),
],
),
try to wrap Text Widget with Padding or set padding to floating action button.
im try to created a verticle button on the left center screen in the flutter. First i created a Raised Button and rotate it using Rotated Box. But it keeping padding left side of the button. i dont want padding on the left side. How to possible it ?
body: Stack(
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: RotatedBox(
quarterTurns: 1,
child: RaisedButton(padding: EdgeInsets.all(0), color: Clr.primaryClr, onPressed: () {}, child: Text('SPORTS')))),
pages[currentPage],
],
),
You can remove padding of button with:
RaisedButton(materialTapTargetSize: MaterialTapTargetSize.shrinkWrap)
Is it possible to move the floatingActionButton up by 50 pixels?
I have a floatingActionButton in an App that uses firebase_admob and the Ads Banner is overlapping on top of the floatingActionButton.
How does one set the floatingActionButton to be 50 pixels from the bottom of the screen?
From the documentation of floatingActionButton I can not seem to pick out how to position the button.
Wrap your FloatingActionButton inside a Padding and add the size you want:
floatingActionButton: Padding(
padding: const EdgeInsets.only(bottom: 50.0),
child: FloatingActionButton(
child: Icon(Icons.remove),
onPressed: () => null,
),
),
It's simple.
class Test extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Container(),
floatingActionButton: Align(
child: FloatingActionButton(onPressed: null),
alignment: Alignment(1, 0.7)),
);
}
}
Use Alignment, as everything is a Widget in Flutter.
I want to have a row of IconButtons, all next to each other, but there seems to be pretty big padding between the actual icon, and the IconButton limits. I've already set the padding on the button to 0.
This is my component, pretty straightforward:
class ActionButtons extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
color: Colors.lightBlue,
margin: const EdgeInsets.all(0.0),
padding: const EdgeInsets.all(0.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
IconButton(
icon: new Icon(ScanrIcons.reg),
alignment: Alignment.center,
padding: new EdgeInsets.all(0.0),
onPressed: () {},
),
IconButton(
icon: new Icon(Icons.volume_up),
alignment: Alignment.center,
padding: new EdgeInsets.all(0.0),
onPressed: () {},
)
],
),
);
}
}
I want to get rid of most of the light blue space, have my icons start earlier on the left, and closer to each other, but I can't find the way to resize the IconButton itself.
I'm almost sure this space is taken by the button itself, 'cause if I change their alignments to centerRight and centerLeft they look like this:
Making the actual icons smaller doesn't help either, the button is still big:
thanks for the help
Simply pass an empty BoxConstrains to the constraints property and a padding of zero.
IconButton(
padding: EdgeInsets.zero,
constraints: BoxConstraints(),
)
You have to pass the empty constrains because, by default, the IconButton widget assumes a minimum size of 48px.
Two ways to workaround this issue.
Still Use IconButton
Wrap the IconButton inside a Container which has a width.
For example:
Container(
padding: const EdgeInsets.all(0.0),
width: 30.0, // you can adjust the width as you need
child: IconButton(
),
),
Use GestureDetector instead of IconButton
You can also use GestureDetector instead of IconButton, recommended by Shyju Madathil.
GestureDetector( onTap: () {}, child: Icon(Icons.volume_up) )
It's not so much that there's a padding there. IconButton is a Material Design widget which follows the spec that tappable objects need to be at least 48px on each side. You can click into the IconButton implementation from any IDEs.
You can also semi-trivially take the icon_button.dart source-code and make your own IconButton that doesn't follow the Material Design specs since the whole file is just composing other widgets and is just 200 lines that are mostly comments.
Wrapping the IconButton in a container simply wont work, instead use ClipRRect and add a material Widget with an Inkwell, just make sure to give the ClipRRect widget enough border Radius 😉.
ClipRRect(
borderRadius: BorderRadius.circular(50),
child : Material(
child : InkWell(
child : Padding(
padding : const EdgeInsets.all(5),
child : Icon(
Icons.favorite_border,
),
),
onTap : () {},
),
),
)
Instead of removing a padding around an IconButton you could simply use an Icon and wrap it with a GestureDetector or InkWell as
GestureDetector(
ontap:(){}
child:Icon(...)
);
Incase you want the ripple/Ink splash effect as the IconButton provides on click wrap it with an InkWell
InkWell(
splashColor: Colors.red,
child:Icon(...)
ontap:(){}
)
though the Ink thrown on the Icon in second approach wont be so accurate as for the IconButton, you may need to do some custom implementation for that.
Here's a solution to get rid of any extra padding, using InkWell in place of IconButton:
Widget backButtonContainer = InkWell(
child: Container(
child: const Icon(
Icons.arrow_upward,
color: Colors.white,
size: 35.0,
),
),
onTap: () {
Navigator.of(_context).pop();
});
I was facing a similar issue trying to render an Icon at the location the user touches the screen. Unfortunately, the Icon class wraps your chosen icon in a SizedBox.
Reading a little of the Icon class source it turns out that each Icon can be treated as text:
Widget iconWidget = RichText(
overflow: TextOverflow.visible,
textDirection: textDirection,
text: TextSpan(
text: String.fromCharCode(icon.codePoint),
style: TextStyle(
inherit: false,
color: iconColor,
fontSize: iconSize,
fontFamily: icon.fontFamily,
package: icon.fontPackage,
),
),
);
So, for instance, if I want to render Icons.details to indicate where my user just pointed, without any margin, I can do something like this:
Widget _pointer = Text(
String.fromCharCode(Icons.details.codePoint),
style: TextStyle(
fontFamily: Icons.details.fontFamily,
package: Icons.details.fontPackage,
fontSize: 24.0,
color: Colors.black
),
);
Dart/Flutter source code is remarkably approachable, I highly recommend digging in a little!
A better solution is to use Transform.scale like this:
Transform.scale(
scale: 0.5, // set your value here
child: IconButton(icon: Icon(Icons.smartphone), onPressed: () {}),
)
You can use ListTile it gives you a default space between text and Icons that would fit your needs
ListTile(
leading: Icon(Icons.add), //Here Is The Icon You Want To Use
title: Text('GFG title',textScaleFactor: 1.5,), //Here Is The Text Also
trailing: Icon(Icons.done),
),
I like the following way:
InkWell(
borderRadius: BorderRadius.circular(50),
onTap: () {},
child: Container(
padding: const EdgeInsets.all(8),
child: const Icon(Icons.favorite, color: Colors.red),
),
),
enter image description here
To show splash effect (ripple), use InkResponse:
InkResponse(
Icon(Icons.volume_up),
onTap: ...,
)
If needed, change icons size or add padding:
InkResponse(
child: Padding(
padding: ...,
child: Icon(Icons.volume_up, size: ...),
),
onTap: ...,
)