Dart 将视图固定到设备底部
我有一个堆栈中的视图,我希望它保持固定在手机底部时,它是转向景观。目前我有以下几点:Dart 将视图固定到设备底部,dart,flutter,Dart,Flutter,我有一个堆栈中的视图,我希望它保持固定在手机底部时,它是转向景观。目前我有以下几点: @override Widget build(BuildContext context) { return new Scaffold( appBar: detectOrientationForAppBar(), backgroundColor: Colors.black, key: _scaffoldKey, body: new Column(
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: detectOrientationForAppBar(),
backgroundColor: Colors.black,
key: _scaffoldKey,
body: new Column(
children: <Widget>[
new Expanded(
child: new Stack(
children: <Widget>[
new Container(
height: double.infinity,
width: double.infinity,
child: new Padding(
padding: const EdgeInsets.all(1.0),
child: new Center(
child: _cameraPreviewWidget(),
),
),
),
_captureControlRowWidget()
],
),
),
],
),
);
}
我试过一些方法,比如使用横轴和主轴对齐,但它总是粘在手机最低的边缘。e、 g如果我将手机放在手机的底部,如果我将手机向任一方向旋转90度,手机的小部件应该位于手机的右侧。此时,你的主体是一个柱,因此,正如预期的那样,你的控制小部件位于相机预览下方。在横向模式下,您希望控制小部件位于相机预览的右侧,这意味着您希望主体成为一行
您可以通过将顶部列更改为Flex来实现这一点,Flex是一个开关可选的行/列
@override
Widget build(BuildContext context) {
bool landscape = MediaQuery.of(context).orientation == Orientation.landscape;
return new Scaffold(
appBar: detectOrientationForAppBar(),
backgroundColor: Colors.black,
key: _scaffoldKey,
body: new Flex(
direction: landscape ? Axis.horizontal : Axis.vertical,
您必须在captureControlRowWidget中进行相同的更改,将其列和行设置为方向敏感的Flex
@override
Widget build(BuildContext context) {
bool landscape = MediaQuery.of(context).orientation == Orientation.landscape;
return new Scaffold(
appBar: detectOrientationForAppBar(),
backgroundColor: Colors.black,
key: _scaffoldKey,
body: new Flex(
direction: landscape ? Axis.horizontal : Axis.vertical,