只有在方向为横向的情况下,我才能为列设置 MainAxisAlignment.spaceEvenly 。因此,它不会改变我的纵向布局。
class _MobileLayout extends StatelessWidget {
const _MobileLayout({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
var orientation = MediaQuery.of(context).orientation;
return Container(
width: orientation == Orientation.portrait ? 250 : 100,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 16,
color: Colors.black12,
)
],
),
child: Column(
children: AppDrawer.getDrawerOptions(),
),
);
}
}
我已经尝试了多种方法
答案 0 :(得分:1)
默认值为MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start,
,因此您可以执行以下操作;
child: Column(
mainAxisAlignment: orientation == Orientation.landscape?
MainAxisAlignment.spaceEvenly : MainAxisAlignment.start,
children: AppDrawer.getDrawerOptions(),
),
还将使用portrait
的默认值