Stack multiple icons to flutter IconButton - flutter

I have a IconButton and want to stack two icons to look like
I tried with Row layout like
CircleAvatar(
radius: avatarRadius,
child: IconButton(
icon: Row(
children: [
Icon(
Icons.add,
color: Colors.white,
),
Icon(
Icons.message,
color: Colors.white,
),
]
),
onPressed: _onAddMessageButtonClick,
),
),
But it is giving error
A RenderFlex overflowed by 24 pixels on the right.

Remove IconButton widgets
Try this
CircleAvatar(
radius: 40,
child: GestureDetector(
onTap: (){
// perform click here
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.add,
color: Colors.white,
),
Icon(
Icons.message,
color: Colors.white,
),
]
),
),
),
OUTPUT

Related

I have a problem with displaying in a Row in flutter

I'm a beginner in flutter, I want to display a text on the far left and a button on the far right in a container, here is my code:
Container(
width: double.infinity,
margin: const EdgeInsets.all(10),
padding: const EdgeInsets.all(8.0),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('TEXT'),
IconButton(
onPressed: () {},
icon: Icon(
Icons.price_change_outlined,
color: Colors.blue,
))
],
),
),
Use mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('TEXT'),
IconButton(
onPressed: () {},
icon: Icon(
Icons.price_change_outlined,
color: Colors.blue,
))
],
),
You can find more about Row and layout
An alternative to the above solutions is to use a Spacer widget.
An advantage to this approach is that you can easily add more widgets to whatever side you want and keep the spacing in between.
Row(
children: [
Text('TEXT'),
const Spacer(),
IconButton(
onPressed: () {},
icon: Icon(
Icons.price_change_outlined,
color: Colors.blue,
),
)
]
)

Remove extra space between two IconButton in ROw

I want to remove some extra space between two IconButton in Row widget
I tried much more but still not able to remove space between widgets
Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("Home",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: Colors.black
)
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
IconButton(
icon: Icon(
Icons.edit,
color: Colors.black,
size: 20,
),
onPressed: () {
IntelUtility.navigateToScreen(
context, EditHomeAddressScreen()
);
},
),
IconButton(
icon: Icon(
Icons.delete,
color: Colors.black,
size: 20,
),
onPressed: () {},
),
],
),
],
),
],
),
Please help to solving this issue i am in trouble :(
Instead of using IconButton,
you can use CupertinoButton like this :
CupertinoButton(
minSize: double.minPositive,
padding: EdgeInsets.zero,
child: Icon(
Icons.delete,
color: Color.black,
size: 20
),
onPressed: () {},
)
Add param padding: EdgeInsets.all(0) to IconButton.
IconButton(
padding: EdgeInsets.all(0),
icon: Icon(
Icons.delete,
color: Colors.black,
size: 20,
),
onPressed: () {},
)
Your answer is BoxConstraints
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
IconButton(
constraints: BoxConstraints.tight(Size.fromWidth(30)),
icon: Icon(
Icons.edit,
color: Colors.black,
size: 20,
),
onPressed: () {
IntelUtility.navigateToScreen(
context, EditHomeAddressScreen()
);
},
),
IconButton(
constraints: BoxConstraints.tight(Size.fromWidth(30)),
icon: Icon(
Icons.delete,
color: Colors.black,
size: 20,
),
onPressed: () {},
),
],
),
You can change constraints: BoxConstraints.tight(Size.fromWidth(30)), whatever you want

I cannot used Icon(Icons.star, color: Colors.green[500]), error

The following assertion was thrown building Icon(IconData(U+0E838), color: Color(0xff4caf50),
Invalid placement of the icon widget.
it suppost to be like this.
child: Icon(
Icons.star,
size: 25.0,
color: Colors.lightBlueAccent,
),
or
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(Icons.star),
Icon(Icons.access_alarm),
],
),

How to code add button like zoom at in Flutter

I need to implement a button like a zoom at when we click on "+" the value should be incremented and when we click "-" the value should be decremented and the calculate value should be shown in the middle of "+" and "-" on the button.
RawMaterialButton(
fillColor: Colors.green,
splashColor: Colors.greenAccent,
onPressed: onPressed,
shape:const StadiumBorder(),
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Row(
children: <Widget>[
const Icon(
Icons.add,
color: Colors.white,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("ADD",
style: TextStyle(
color: Colors.white,
),
),
),
const Icon(
Icons.remove,
color: Colors.white,
)
],
),
));
**but I don't know how to create two different buttons
I need just design part **
In a row, you can use IconData(-), Text(5) and IconData(+) like:
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: Material(
child: IconButton(
icon: Icon(Icons.remove_circle_outline,
color: Colors.black),
onPressed: () {
_decrementValue(value);
}),
)),
Expanded(
child: Text(
'${value}',
textAlign: TextAlign.center,
)),
Expanded(
child: Material(
child: IconButton(
icon: Icon(Icons.add_circle_outline,
color: Colors.black),
onPressed: () {
_incrementValue(value);
}),
)),
],
),
)
And in _incrementValue() and _decrementValue() method, you can use your logic.

How to achieve dynamic text under icon in the best way

I'm trying to implement 2 Icons in a Row and under each Icon some text
My current implementation:
ButtonBar(
alignment: MainAxisAlignment.spaceAround,
children: <Widget>[
IconButton(
icon: Icon(
Icons.directions_car,
size: 55.0,
),
onPressed: () {},
),
IconButton(
icon: Icon(
Icons.streetview,
size: 55.0,
),
onPressed: () {},
),
],
),
Padding(
padding: const EdgeInsets.fromLTRB(18.0, 10.0, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text('some text',
style: TextStyle(
fontSize: 16.0
),
),
Text('some text'),
],
),
),
My problem is that my text should be dynamic, So every time the text changed, the location of my text changes and sometimes it look really ugly.
How can in place the text in a better way that is posted here?
try this.. so what I have done is I added both Icon and Text inside a Column so they will behave as a group
ButtonBar(
alignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Column(
children: <Widget>[
IconButton(
padding: EdgeInsets.zero,
icon: Icon(
Icons.directions_car,
size: 55.0,
),
onPressed: () {},
),
SizedBox(
height: 10,
),
Text('some text'),
],
),
Column(
children: <Widget>[
IconButton(
padding: EdgeInsets.zero,
icon: Icon(
Icons.streetview,
size: 55.0,
),
onPressed: () {},
),
SizedBox(
height: 10,
),
Text('some text'),
],
),
],
),