At the moment, I am using the following bit of code :
body: new Container( child: new Column( crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ new MaterialButton( height: 120.0, child: new Column( children: <Widget>[ new Icon( Icons.av_timer, size: 100.0, ), new Text('TIMER'), ], ), onPressed: null, ), new MaterialButton( height: 120.0, child: new Column( children: <Widget>[ new Icon(Icons.alarm_add, size: 100.0), new Text('ALARM'), ], ), onPressed: null, ) ])));
However, I have had to "hardcode" the Icon size to 100.0 and the height of the MaterialButton to 120.0.
I would like the MaterialButton to take as much space as possible (50% of the screen for each), and I would like the Icons to "fit nicely" in that space, ideally along with the Text scaling as well.
I haven't found the way to do that in Flutter yet. If it's not a good idea to try to do this (I would like it to use the entire space of the screen on any device) please let me know why ?
You can increase the size of Icon to a required value by assigning the size property with specific double value.
Icons occupy a square with width and height equal to size. Defaults to the current IconTheme size, if any. If there is no IconTheme, or it does not specify an explicit size, then it defaults to 24.0.
To change the icon button color on press, add a highlightColor property to the IconButton widget. Inside the highlightColor assign the color of your choice.
You can use LayoutBuilder to dynamically get the parent size during build.
A working example :
void main() { runApp(new MaterialApp( home: new TestIcon(), )); } class TestIcon extends StatelessWidget { @override Widget build(BuildContext context) { return new Container( color: Colors.white, child: new LayoutBuilder(builder: (context, constraint) { return new Icon(Icons.access_alarms, size: constraint.biggest.height); }), ); } }
Screenshot:
Use FittedBox
:
SizedBox.fromSize( size: Size.fromRadius(200), child: FittedBox( child: Icon(Icons.add), ), )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With