How to automatically size Icons in Flutter to be as big as possible

前端 未结 3 521
别跟我提以往
别跟我提以往 2021-02-07 00:47

At the moment, I am using the following bit of code :

   body: new Container(
            child: new Column(
                crossAxisAlignment: CrossAxisAlignm         


        
3条回答
  •  花落未央
    2021-02-07 01:08

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

提交回复
热议问题