Sub topic 9
Layouts That Survive Large Text
Assume you know basic Dart, Flutter layouts, and StatelessWidget and StatefulWidget. This chapter focuses on text scaling: the user setting that enlarges text for easier reading. A layout that works at the default size can overflow or hide controls when text becomes much larger.
Read the User's Text Scale
Flutter exposes the current text scale through MediaQuery. Prefer TextScaler APIs such as MediaQuery.textScalerOf(context) instead of multiplying sizes with the older textScaleFactor property.
Do not treat the default text size as a fixed design boundary. Let text wrap, let controls grow vertically, and allow the page to scroll when its content becomes taller than the screen.
import 'package:flutter/material.dart';
class ScalableSettingsPage extends StatelessWidget {
const ScalableSettingsPage({super.key});
@override
Widget build(BuildContext context) {
final scaler = MediaQuery.textScalerOf(context);
return Scaffold(
appBar: AppBar(title: const Text('Settings')),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'Choose how notifications should work.',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
ConstrainedBox(
constraints: BoxConstraints(
minHeight: scaler.scale(48),
),
child: FilledButton(
onPressed: () {},
child: const Text('Save notification settings'),
),
),
],
),
),
);
}
}The SingleChildScrollView prevents content below the fold from becoming unreachable. The minimum button height grows with the text scale, but the button can also become taller if its label wraps.
Avoid Fixed Heights and Rigid Rows
A common error is placing a long label in a Row beside a fixed-width control. At a large scale, the label may overflow. Use Expanded or Flexible so the text receives a bounded, flexible width.
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Text(
'Send a reminder before each scheduled event',
softWrap: true,
),
),
const SizedBox(width: 12),
Switch(
value: true,
onChanged: (_) {},
),
],
)Use Wrap when items can move to another line. Use LayoutBuilder when the arrangement should change at a particular available width. Avoid using FittedBox to shrink important text. Shrinking text can make it technically fit while making it difficult to read.
Check More Than One Scale
Test at the platform's largest practical text setting, not only at the default scale. Look for clipped labels, overlapping controls, inaccessible buttons, and dialogs that cannot scroll.
Also check text inside cards, list tiles, bottom sheets, and error messages. A screen can pass its first visual inspection while a translated label or validation message still overflows.
Exercise
A settings row contains a long label and a switch. What should you change first if the label overflows at large text sizes?
Show answer
Give the label an Expanded or Flexible child, allow it to wrap, and avoid a fixed row height. If the whole page becomes taller, make the page scrollable.