FlutterBasic 2 min read

Flutter gestures, selection and accessible controls

Prefer semantic controls for ordinary actions, use GestureDetector for custom interaction and keep hit targets usable.

On this page

A tap is not the only way to activate an interface. Keyboard users and assistive technologies need a control’s role, state and action to be understandable.

Prefer an existing control

CheckboxListTile, SwitchListTile and buttons already express common interaction semantics. Use GestureDetector for behavior that is genuinely custom, and then supply the missing focus, keyboard and semantic handling.

Make selection visible

Do not communicate a selected value only through a subtle color change. Use the control’s selected state, a check mark or explanatory text as appropriate.

Worked example

This is a complete example. Open it with Run example, then use Run inside DartPad.

main.dart
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: PreferencePage()));
class PreferencePage extends StatefulWidget {
  const PreferencePage({super.key});
  @override
  State<PreferencePage> createState() => _PreferencePageState();
}
class _PreferencePageState extends State<PreferencePage> {
  bool reminders = false;
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Preferences')),
    body: SwitchListTile(title: const Text('Practice reminders'),
      subtitle: const Text('Store a local reminder preference.'),
      value: reminders, onChanged: (value) => setState(() => reminders = value)),
  );
}

Read the result

The setting changes in memory. It does not schedule an actual notification. This distinction keeps the example honest: persistence and notification permissions are separate features.

Separate the preference from the side effect it may enable

Toggling this example changes a local boolean. It does not request a notification permission, schedule a reminder or save the value across launches. Those are separate operations with separate success and failure states.

This separation makes the first interaction understandable. Once it works with pointer, keyboard and spoken state, add preference persistence and explicitly handle its completion. A platform notification feature then needs the target-specific permission and scheduling workflow.

Using a semantic control gives the user a recognizable role and on/off state. A visually similar colored rectangle with a gesture callback would require you to implement those keyboard, focus and semantic expectations yourself. Compare the two while reviewing accessible interfaces .

Practice and verification

Use Tab and Space where supported, then inspect the spoken label and on/off state with a screen reader. Add persistence only after the interaction is understandable.

How this topic connects

Understand first

Apply it next

Lesson progressMark complete after checking the example and exercise.

Find your next idea

Search lessons, code examples and projects.

Type a few words to start exploring.