Чтобы изменить в зависимости от ориентации устройства, вы можете сделать:
Orientation orientation = MediaQuery.of(context).orientation;
return orientation == Orientation.portrait
? Column(children: <Widget>[])
: Row(children: <Widget>[]);
Я написал помощник для этого (от столбца к строке).
import 'package:flutter/material.dart';
class OrientationSwitcher extends StatelessWidget {
final List<Widget> children;
const OrientationSwitcher({Key key, this.children}) : super(key: key);
@override
Widget build(BuildContext context) {
Orientation orientation = MediaQuery.of(context).orientation;
return orientation == Orientation.portrait
? Column(children: children)
: Row(children: children);
}
}
И для его использования ...
Widget build(BuildContext context) {
return OrientationSwitcher(
children: <Widget>[
// place children here like its a column or row.
]
)
}
Вы также можете сделать это с помощью Flex () или любого другого виджета.
Кроме того, есть и другиекроме ориентации, доступны опции, не забудьте взглянуть на реализацию MediaQuery.of (context) в документации Flutter.