Sub topic 12
Respecting reduced motion, bold text and other settings
Users change accessibility settings in the operating system, not in your app. This chapter covers how Flutter passes those settings to your widgets and what your code should do with each one. It assumes you know MediaQuery, StatefulWidget lifecycle methods, and the text scaling material from the previous chapter.
How settings reach your widgets
The operating system reports the user's accessibility choices to the Flutter engine. The framework exposes them on MediaQueryData, and MediaQuery rebuilds any widget that reads them when they change. You don't poll or subscribe.
Use the specific static accessors, such as MediaQuery.disableAnimationsOf(context), instead of MediaQuery.of(context). An accessor registers a dependency on one property. With of, your widget rebuilds whenever any media property changes, including keyboard insets and window size.
The settings you can read
| Accessor | User setting (typical name) | What it means for your app |
|---|---|---|
| `disableAnimationsOf` | iOS Reduce Motion, Android Remove animations | Skip or shorten non-essential motion |
| `boldTextOf` | iOS Bold Text, Android Bold text | Text gets heavier and wider |
| `highContrastOf` | iOS Increase Contrast, Android high contrast text | Use stronger colors and borders |
| `invertColorsOf` | iOS Invert Colors | Colors are inverted by the OS |
| `accessibleNavigationOf` | Screen reader or similar assistive tool active | Don't depend on touch-only interaction |
| `onOffSwitchLabelsOf` | iOS On/Off Labels | Switches should show 0/1 style marks |
| `textScalerOf` | Font size on both platforms | Layout must grow with text |
Setting names differ between OS versions and device makers. Some options may be missing on older Android versions. Always test on a real device and look in the system accessibility menu.
Reduced motion
Reduced motion exists because large movement, parallax, zooming and endless looping can cause nausea, dizziness or distraction for people with vestibular disorders. It also helps people who simply find motion tiring.
Reduced motion does not mean "no feedback". Remove movement that is decorative, large or repeating. Keep changes the user needs to notice, but deliver them with a fade, a color change or an instant swap.
The simplest case is a one-off animation. Read the setting and choose the duration:
import 'package:flutter/material.dart';
class ContinueButton extends StatelessWidget {
const ContinueButton({super.key});
@override
Widget build(BuildContext context) {
final scaler = MediaQuery.textScalerOf(context);
final reduceMotion = MediaQuery.disableAnimationsOf(context);
return AnimatedContainer(
duration: reduceMotion ? Duration.zero : const Duration(milliseconds: 300),
constraints: BoxConstraints(minHeight: scaler.scale(48)),
child: const Center(child: Text('Continue')),
);
}
}The container uses minHeight, not height, so the button grows with the text. The Duration.zero branch makes the container jump to its new size.
Looping animations need a lifecycle
An animation that repeats needs more care. If the setting changes while your widget is on screen, you have to stop or start the controller yourself. didChangeDependencies runs whenever a MediaQuery value you depend on changes, so it is the right place to react.
import 'package:flutter/material.dart';
class PulsingDot extends StatefulWidget {
const PulsingDot({super.key});
@override
State<PulsingDot> createState() => _PulsingDotState();
}
class _PulsingDotState extends State<PulsingDot>
with SingleTickerProviderStateMixin {
late final AnimationController _controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 1),
);
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (MediaQuery.disableAnimationsOf(context)) {
_controller
..stop()
..value = 1;
} else if (!_controller.isAnimating) {
_controller.repeat(reverse: true);
}
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return FadeTransition(
opacity: Tween<double>(begin: 0.4, end: 1.0).animate(_controller),
child: const SizedBox(
width: 16,
height: 16,
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
),
),
);
}
}When reduced motion is on, the dot stays at full opacity and no ticker runs. When the user turns it off again, the pulse resumes.
Testing the setting
Widget tests can fake the accessibility features. A running ticker is easy to detect, so you can assert that nothing animates:
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
// Assumes PulsingDot from the previous listing is imported.
void main() {
testWidgets('pulsing dot stops when animations are disabled',
(tester) async {
tester.platformDispatcher.accessibilityFeaturesTestValue =
const FakeAccessibilityFeatures(disableAnimations: true);
addTearDown(tester.platformDispatcher.clearAccessibilityFeaturesTestValue);
await tester.pumpWidget(
const MaterialApp(home: Scaffold(body: Center(child: PulsingDot()))),
);
expect(tester.hasRunningAnimations, isFalse);
});
}If you remove the check from didChangeDependencies, this test fails, because the repeating controller keeps a ticker alive.
Bold text
When boldText is true, the built-in Text widget merges a bold weight into its style. You get this for free as long as you use Text, TextField and the Material widgets built on them.
You must handle the cases the framework cannot see:
- Text drawn with
TextPainteror inside aCustomPaint. - Text baked into images or rendered by a third-party plugin.
- Fixed-size boxes that were tuned for the regular weight.
Bold glyphs are wider, so a label that fit on one line may now wrap or overflow. Use flexible layouts such as Flexible, Wrap and minHeight constraints, the same fixes you apply for large text. For custom-painted text, read the setting and choose the weight:
final isBold = MediaQuery.boldTextOf(context);
final style = TextStyle(
fontWeight: isBold ? FontWeight.w700 : FontWeight.w400,
);High contrast and inverted colors
MaterialApp has two parameters for high contrast, highContrastTheme and highContrastDarkTheme. The framework switches to them when highContrast is true. If you leave them null, the normal theme is used and the setting has no visible effect.
MaterialApp(
theme: ThemeData(colorSchemeSeed: Colors.indigo),
highContrastTheme: ThemeData(
colorScheme: const ColorScheme.highContrastLight(),
),
highContrastDarkTheme: ThemeData(
colorScheme: const ColorScheme.highContrastDark(),
),
home: const HomePage(),
)For a high-contrast theme, also thicken borders and dividers, and avoid colors that depend on opacity. An inverted-colors setting is applied by the operating system to the whole screen, so photos and videos can look wrong. Check the result on a device. If your content is hard to read when inverted, that is a signal to rely less on color alone.
Limiting text scale
Users who need very large text often set the scale above 2.0. Flutter supports this, and most layouts should simply adapt. Occasionally a fixed-size area such as a tab bar or a bottom-sheet header cannot grow. Clamp the scale there, not for the whole app:
MediaQuery.withClampedTextScaling(
minScaleFactor: 1.0,
maxScaleFactor: 1.5,
child: const TabLabelRow(),
)Screen reader and navigation signals
accessibleNavigationOf tells you an assistive technology is likely active. It's useful in a few places:
- Don't auto-dismiss snack bars or tooltips on a short timer, because a screen reader user may need longer to hear them.
- Offer a visible button as well as a gesture-only action.
- Skip interactions that need precise dragging.
Use it to adjust behavior, not to build a separate, reduced version of your app. Screen reader users should get the same features.
Common mistakes
- Reading
MediaQuery.of(context)instead of the specific accessor, which causes extra rebuilds. - Checking the setting once in
initState.MediaQueryis not available there for dependency tracking, and you won't see later changes. UsedidChangeDependenciesorbuild. - Removing all feedback when motion is reduced. Replace motion with a non-moving cue instead.
- Providing no
highContrastThemeand assuming the setting is handled. - Clamping text scale globally to avoid fixing an overflow.
Exercise
A widget starts a repeating controller in initState and never checks disableAnimationsOf. A user turns on Reduce Motion while the screen is open. Describe what is wrong and how you would fix it so the animation also stops without leaving the screen.
Show answer
The controller keeps repeating because nothing checks the setting, and initState runs only once, so it can't react to later changes. Move the check into didChangeDependencies after reading MediaQuery.disableAnimationsOf(context). If it is true, call stop() and set the controller's value to its resting state. If it is false and the controller isn't animating, call repeat. Because the accessor registers a dependency, didChangeDependencies runs again when the user changes the setting.
Exercise
Your app uses CustomPaint to draw a chart title with TextPainter. With Bold Text turned on, the title looks the same as before. Why, and what do you change?
Show answer
boldText is merged automatically only into the Text widget's style. A TextPainter uses the style you give it, so it ignores the setting. Read MediaQuery.boldTextOf(context) in the widget that owns the painter, pass the result to the painter, and choose a heavier fontWeight when it is true. Because bold text is wider, also check that the title still fits its space.