orientation_picker
A simple convenience widget for Flutter to conditionally display (or hide) other widgets based on device orientation (or aspect ratio).
Usage
OrientationPicker({required Widget portrait, required Widget landscape})
Supply two widgets, one for portrait layout and the other for landscape layout. The widget will pick the appropriate one based on the current orientation.
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: OrientationPicker(
landscape: Text('Now in landscape-mode!'),
portrait: Text('Now in portrait-mode!'),
),
),
);
}
OrientationPicker.portraitOnly(Widget widget)
Supply a widget, which will only be displayed when the orientation is portrait.
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: OrientationPicker.portraitOnly(
Text('Only visible in portrait-mode!'),
),
),
);
}
OrientationPicker.landscapeOnly(Widget widget)
Supply a widget, which will only be displayed when the orientation is landscape.
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: OrientationPicker.landscapeOnly(
Text('Only visible in landscape-mode!'),
),
),
);
}
Documentation
To generate the documentation with dartdoc
:
$ dartdoc
Tests
To run the tests:
$ flutter test
Libraries
- orientation_picker
- A simple convenience widget for Flutter to conditionally display (or hide) other widgets based on device orientation (or aspect ratio).