@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.cyanAccent,
child: Row(
children:[
Container(
width: 120,
height: 120,
color: Colors.red,
),
Container(
width: 120,
height: 120,
color: Colors.deepPurple,
),
],
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.cyanAccent,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: widgets,
mainAxisSize: MainAxisSize.max,
),
),
);
}
MainAxisAlignment.start(默认)
MainAxisAlignment.center
MainAxisAlignment.spaceAround
MainAxisAlignment.spaceBetween
MainAxisAlignment.spaceEvenly 相似于 spaceAround
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.cyanAccent,
child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
children: widgets,
mainAxisSize: MainAxisSize.max,
),
),
floatingActionButton: FloatingActionButton(
onPressed: switchWidget,
child: Icon(Icons.undo),
),
);
}
MainAxisSize.max(比照背景色即可发现区别)
MainAxisSize.min
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(width: MediaQuery.of(context).size.width,
height: 500,
color: Colors.cyanAccent,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: widgets,
mainAxisSize: MainAxisSize.min,
),
),
),
);
}
CrossAxisAlignment.start
CrossAxisAlignment.center
CrossAxisAlignment.end
CrossAxisAlignment.stretch
CrossAxisAlignment.baseline(设置该属性时必须配合 textBaseline 属性)