17、Flutter Widget - Spacer;

470 阅读1分钟

  RowColumn有可以用来均匀分配子Widget的属性mainAxisAlignment

Row(
   mainAxisAlignment:MainAxisAlignment.spaceAround,
   children:[
    MyBox(),
    MyBox(),
    MyBox()
   ],
 )

  如果你想更个性化的实现子Widget的空间分配,可以使用Spacer;

Row (
  children:[
    MyBox(),
    Spacer(),
    MyBox(),
    Spacer(),
    MyBox(),
],
)

  只需要添加Spacer实例到其他Widget之间,他们就会扩大并建立额外的空间。可以使用默认为 1的flex属性来定制其相对的尺寸:

Row (
  children:[
    MyBox(),
    Spacer(),
    MyBox(),
    Spacer(flex:3),
    MyBox(),
],
)