Sub topic 15
Foldables and Multi-Display Considerations
This chapter assumes you know Dart 3 switch expressions, Flutter widget trees, Row, Column, Scaffold, and MediaQuery. It also assumes you can run a Flutter app on an emulator or physical device.
Foldable phones and multi-display devices add another layout constraint: the app window may contain a hinge, fold, cutout, or more than one display region. Flutter exposes these regions as display features. A display feature is a physical part of the device that affects where content can appear.
Display features and safe regions
Read display features from MediaQuery. Each feature has a bounds rectangle in the window's logical coordinate system. The rectangle tells you where the hinge, fold, or cutout is located.
| Feature | Layout concern |
|---|---|
| Hinge | Content must not be placed under the physical hinge |
| Fold | Content may need to avoid the fold or react to its posture |
| Cutout | Content must avoid an area occupied by hardware |
A normal phone or desktop window usually has no hinge or fold, so displayFeatures is empty. Your layout should therefore keep a useful single-window fallback.
A vertical hinge often separates a left pane from a right pane. A horizontal hinge often separates a top pane from a bottom pane. Use the feature's rectangle rather than guessing from the device model.
import 'package:flutter/material.dart';
class FoldableHome extends StatelessWidget {
const FoldableHome({super.key});
@override
Widget build(BuildContext context) {
final size = MediaQuery.sizeOf(context);
final features = MediaQuery.of(context).displayFeatures;
DisplayFeature? splitFeature;
for (final feature in features) {
final isSplit = feature.type == DisplayFeatureType.hinge ||
feature.type == DisplayFeatureType.fold;
if (isSplit) {
splitFeature = feature;
break;
}
}
if (splitFeature == null) {
return const Center(child: Text('Single display'));
}
final bounds = splitFeature.bounds;
final isVertical = bounds.height > bounds.width;
if (isVertical) {
return Row(
children: [
SizedBox(
width: bounds.left,
child: const ColoredBox(
color: Colors.blue,
child: Center(child: Text('Left pane')),
),
),
SizedBox(width: bounds.width),
SizedBox(
width: size.width - bounds.right,
child: const ColoredBox(
color: Colors.orange,
child: Center(child: Text('Right pane')),
),
),
],
);
}
return Column(
children: [
SizedBox(
height: bounds.top,
child: const ColoredBox(
color: Colors.blue,
child: Center(child: Text('Top pane')),
),
),
SizedBox(height: bounds.height),
SizedBox(
height: size.height - bounds.bottom,
child: const ColoredBox(
color: Colors.orange,
child: Center(child: Text('Bottom pane')),
),
),
],
);
}
}The example reserves the feature's entire rectangle. This is important because a hinge can have physical width. A zero-width fold may still represent a meaningful boundary, so treat it as a layout boundary even when the gap is visually small.
Multi-display decisions
A foldable does not always require two panes. Choose a layout based on the available regions and the task:
- Use one pane when the current screen needs focus, such as a form or reading view.
- Use list-detail when the two regions support navigation and content together.
- Keep related controls on the same side of a hinge.
- Avoid placing a text field, button, or drag target across a fold.
- Recompute the layout when the window moves, rotates, or changes posture.
Do not assume that two physical screens always mean two equal regions. Use the reported rectangles and let each pane receive its own constraints.
Exercise
Why should a foldable layout use DisplayFeature.bounds instead of simply dividing the window width in half?
Show answer
The hinge or fold may be off-center, have physical width, or run horizontally. Its bounds identify the actual region that content must avoid.