Best practice for effectively scale this UI according to different screen sizes in Flutter

后端 未结 2 1971
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 08:27

I\'m doing a UI in flutter and right now it look great on my emulator but I\'m afraid it will break if screen size is different. What is the best practice to prevent this, e

2条回答
  •  一生所求
    2020-12-20 08:53

    Use flutter widget LayoutBuilder every time you use it it'll give you a BoxConstraint what it can do is it'll tell you what space (maxHeight, maxWidth etc) is available for further children down the widget tree, you use that detail to divide the space within the children

    For example

    if you want to divide the available width within 3 Containers do

    Row(
              children: [
                Container(
                  width: constraints.maxWidth / 3,
                ),
                Container(
                  width: constraints.maxWidth / 3,
                ),
                Container(
                  width: constraints.maxWidth / 3,
                ),
              ],
            ),
    

    you can do the same with the font sizes

提交回复
热议问题