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

前端 未结 3 520
别跟我提以往
别跟我提以往 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:06

    Thanks to Darky, I ended up using the LayoutBuilder, along with the Expanded Widget, the Column Widget, and the use of the flex parameter to give the right proportions. As for the text sizing, I couldn't find a better way than using some kind of ratio based on the available biggest height.

    body: new Container(
                child: new Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                  new Expanded(
                      child: new MaterialButton(
                          child: new Column(
                            children: [
                              new Expanded(
                                flex: 4,
                                child: new LayoutBuilder(
                                    builder: (context, constraint) {
                                  return new Icon(
                                    Icons.timer,
                                    size: constraint.biggest.height,
                                  );
                                }),
                              ),
                              new Expanded(child:
                                  new LayoutBuilder(builder: (context, constraint) {
                                return new Text('TIMER',
                                    style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: constraint.biggest.height/30.0));
                              })),
                            ],
                          ),
                          onPressed: () {
                            showTimePicker(
                              context: context,
                              initialTime: new TimeOfDay.now(),
                            );
                          })),
                  new Expanded(
                      child: new MaterialButton(
                          child: new Column(
                            children: [
                              new Expanded(
                                flex: 4,
                                child: new LayoutBuilder(
                                    builder: (context, constraint) {
                                      return new Icon(
                                        Icons.alarm,
                                        size: constraint.biggest.height,
                                      );
                                    }),
                              ),
                              new Expanded(child:
                              new LayoutBuilder(builder: (context, constraint) {
                                return new Text('ALARM',
                                    style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: constraint.biggest.height/30.0));
                              })),
                            ],
                          ),
                          onPressed: () {
                            showTimePicker(
                              context: context,
                              initialTime: new TimeOfDay.now(),
                            );
                          })),
                ]))
    

提交回复
热议问题