At the Flutter documentation, the recommended way for building an IconButton
widget with opaque colored background is the following:
class IconButtonExample extends StatelessWidget {
const IconButtonExample({super.key});
@override
Widget build(BuildContext context) {
return Material(
color: Colors.white,
child: Center(
child: Ink(
decoration: const ShapeDecoration(
color: Colors.lightBlue,
shape: CircleBorder(),
),
child: IconButton(
icon: const Icon(Icons.add),
color: Colors.white,
onPressed: () {},
),
),
),
);
}
}
However, if I want to decrease the size of the overall size of the button to 24, like the following:
child: Ink(
height: 24,
width: 24,
decoration: ShapeDecoration(
the icons is not centered anymore, although its content size would fit in the mentioned size.
Even decreasing the Icon
widget size itself to 14, don’t give a satisfying result, and using Center
widget and Alignment.center
also do not solve it.
I’m not willing to use FAB widget, because FAB literally is supposed to float in the screen. The widget I’m trying to achieve is supposed to exist as an generic widget.