Sub topic 12
Respecting reduced motion, bold text and other settings
This chapter assumes you can build Flutter layouts and use StatelessWidget and StatefulWidget. It focuses on reading platform accessibility settings through MediaQuery and adapting your UI without creating a separate layout for every device.
Read accessibility settings
Flutter exposes many system preferences through the MediaQuery inherited widget. An inherited widget provides data to widgets below it in the widget tree. Use the specific MediaQuery methods instead of reading unrelated values from MediaQueryData.
Common settings include:
| Setting | Flutter API | Typical response |
|---|---|---|
| Text size | `MediaQuery.textScalerOf` | Allow text and containers to grow |
| Reduced motion | `MediaQuery.disableAnimationsOf` | Remove or shorten animations |
| Bold text | `MediaQuery.boldTextOf` | Preserve readable weight and spacing |
| High contrast | `MediaQuery.highContrastOf` | Increase visual separation |
| Accessible navigation | `MediaQuery.accessibleNavigationOf` | Avoid time-limited interactions |
The setting describes a user preference. It does not tell you exactly how to redesign the screen. Choose an adaptation that keeps the same task and information available.
flowchart TD
A[Platform accessibility setting] --> B[MediaQuery]
B --> C[Flutter widget]
C --> D[Adapt animation, size, contrast, or timing]
D --> E[Same task remains available]Respect reduced motion
Animations can help users understand a state change, but movement can cause discomfort or make an interface harder to use. Check disableAnimationsOf before starting a transition.
import 'package:flutter/material.dart';
class ContinueButton extends StatelessWidget {
const ContinueButton({super.key});
@override
Widget build(BuildContext context) {
final reduceMotion = MediaQuery.disableAnimationsOf(context);
return AnimatedContainer(
duration: reduceMotion
? Duration.zero
: const Duration(milliseconds: 300),
padding: const EdgeInsets.all(16),
color: Colors.blue,
child: const Text(
'Continue',
style: TextStyle(color: Colors.white),
),
);
}
}Do not only disable decorative animation. Make sure the state change still happens. For example, replace a sliding panel with an immediate change, but keep the panel's content and controls available.
Support large and bold text
A user may increase text size or enable bold text. Avoid fixed heights around text because the text can wrap or require more lines. Prefer minimum constraints, flexible layouts, and scrolling when content becomes taller.
Text normally responds to the current text scaler. Your surrounding layout must give it room to do so. Test at large text sizes, including text inside buttons, rows, dialogs, and list items.
Bold text can change line widths. If your design uses custom font weights, check that labels still fit when MediaQuery.boldTextOf(context) is true. Do not communicate meaning only through weight. Combine weight with a label, icon, or shape.
Respect other preferences
High contrast may require stronger borders or clearer color differences. Accessible navigation can indicate that users need more time or rely on non-touch navigation. Avoid auto-dismissing important messages and do not make a gesture the only way to complete an action.
Test settings together. Large text and bold text can expose overflow that neither setting reveals alone. Reduced motion can also affect focus and loading feedback, so provide another clear indication when work completes.
Exercise
What should a widget do when MediaQuery.disableAnimationsOf(context) returns true?
Show answer
It should remove or shorten nonessential animation while keeping the resulting state and task available immediately.