Enhancing Flutter Apps with Semantics, MergedSemantics, and ExcludeSemantics for Accessibility and SEO

Syed Abdul Basit
3 min readOct 18, 2023

--

Introduction

In today’s ever-evolving digital landscape, the way an application communicates its intent and functionality is paramount. In Flutter, the Semantics widget is used to annotate a specific widget or part of the app’s UI with metadata that accessibility tools, search engines, and other semantic analysis software can understand. Beyond just ensuring our apps are user-friendly for those with disabilities, such as visual impairment, semantics play a crucial role in enhancing discoverability (SEO) and aligning with modern web standards. Dive with us into the intricacies of ExcludeSemantics, MergeSemantics, and Semantics to unlock an elevated user experience.

1. Semantics

What is it?
The Semantics widget annotates the widget tree with a description (metadata) of the meaning of the widgets. It's especially used to make your apps accessible for users of screen reading software.

Key Features:

  • label: Describes the widget in a brief statement.
  • hint: Provides additional guidance on how to interact with the widget.
  • enabled: Indicates if the widget is interactive.
  • readOnly: Marks input elements as read-only.

Note: Regular users won’t see these descriptions, but users with screen readers will hear them.

Example:

Semantics(
label: 'Play button',
hint: 'Double tap to play the video',
child: Icon(Icons.play_arrow),
)

2. ExcludeSemantics

What is it?
ExcludeSemantics widget is used to exclude specific parts of the widget tree from the semantic tree, thus making it inaccessible to screen reading tools.

When to use?

When certain visual data is redundant or might clutter the user’s screen reader experience.

In cases where visual representation doesn’t convey meaningful data.

Example:

ExcludeSemantics(
excluding: true,
child: Image.asset('visual_background.png'),
)

3. MergeSemantics

What is it?
In cases where multiple widgets are used to produce a single logical result, MergeSemantics will combine their individual semantic information into one entity.

Key Benefit:

Ensures that screen readers treat the cluster of widgets as a single interactive element.

Example:

MergeSemantics(
child: Row(
children: [
Icon(Icons.thumb_up),
Text('Like'),
],
),
)

Understanding Screen Readers

Screen readers are assistive software designed to read out digital content. They’re used mainly by people with visual impairments. Instead of reading the screen visually, users hear the content. It narrates the text, describes images, and provides feedback as users navigate through the app or website. For developers and testers, ensuring that apps are screen reader-friendly is essential for accessibility.

Testing with Screen Readers: Tools to Know

1. Automated Testing Tools:

A widget named SemanticsDebugger. Wrapping your app with this widget provides a visual overlay that shows the semantic annotations of widgets. It helps developers visualize how assistive technologies like screen readers would interpret their app.

runApp(
SemanticsDebugger(child: MyApp()),
);

Android:

  • Accessibility Scanner: It’s a tool by Google that suggests accessibility improvements for Android apps without requiring technical skills. Just run it on your device, and it’ll provide suggestions.
  • TalkBack: It’s the built-in screen reader for Android. Interact with your app using TalkBack to understand the experience of a visually impaired user.

iOS:

  • VoiceOver: It’s the built-in screen reader for iOS devices. Enable it from accessibility settings and try navigating your app.
  • Accessibility Inspector: This tool is part of Xcode. It allows you to inspect the accessibility properties of each element in your app.

2. Manual Testing:

Beyond automated tools, you should manually test various aspects:

  • Keyboard Navigation: Ensure that all interactive elements can be navigated using a keyboard or virtual keyboard.
  • Touch Target Size: Ensure touch targets are sufficiently large and have enough spacing from each other.
  • Color and Contrast: Ensure there’s enough contrast between foreground and background colors. Also, make sure the app is usable for those with color blindness.
  • Zoom and Scale: Test if users can zoom or scale the app UI without breaking the layout or functionality. This is crucial for users with low vision.
  • Labels and Readouts: Ensure all interactive elements have descriptive labels, especially custom buttons or unconventional UI elements.

Conclusion

Embracing Flutter’s Semantics, ExcludeSemantics, and MergeSemantics widgets not only enhances the accessibility of your apps but also contributes to improved discoverability and alignment with modern web standards. By considering the needs of users with disabilities and leveraging these tools, developers can create applications that are more inclusive and user-friendly for everyone, while also optimizing their visibility in search engines. Accessibility and SEO go hand in hand in today’s digital landscape, and Flutter provides the tools to excel in both areas.

--

--