accessibility 1.1.1 copy "accessibility: ^1.1.1" to clipboard
accessibility: ^1.1.1 copied to clipboard

An all-in-one solution to enhance your project with accessibility features.

Flutter Accessibility Package

build codecov License: MIT Pub Documentation Languages Test

Flutter Accessibility Package #

An all-in-one solution to enhance your project with accessibility features. Available in 80+ languages. 100% documented.

This package implements accessibility features according to the WCAG 2.1 AA guidelines, focusing on:

Check out the Live web demo.

Features #

  • Text Settings

    • Text scale factor
    • Line height
    • Letter spacing
    • Word spacing
    • Font weight
    • Text alignment
  • Color Settings

    • Text color customization
    • Background color customization
    • Color profiles for different user needs
  • Theme Settings

    • Light/dark mode
    • High contrast themes
    • Complex effect mode toggle
    • Accessibility-enhanced theme presets
  • Persistence Support

    • Settings are saved between sessions
    • Easy restoration of default settings
  • Internationalization Support

    • Multiple language support
    • Localized accessibility settings

Usage #

Wrap your app with AccessibilityInitializer and pass down your AppThemes instance:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  final sharedPreferencesWithCache = await createSharedPreferencesWithCache();
  final sharedPreferencesService = SharedPreferencesServiceWithCache(
    sharedPreferencesWithCache,
  ); // or else if you use legacy SharedPreferences
  // const sharedPreferencesService = SharedPreferencesServiceLegacy();
  final accessibilitySettings =
      await sharedPreferencesService.getLocalStorageAccessibilitySettings();

  final appThemes = AppThemes.fromColorSchemes(
    lightColorScheme:               // your light color scheme
    darkColorScheme:                // your dark color scheme
    textTheme:                      // your text theme
  ); // or use AppThemes() default constructor for finer control

  runApp(
    AccessibilityInitializer(
      sharedPreferencesService: sharedPreferencesService,
      accessibilitySettingsCollection: accessibilitySettings,
      child: MyApp(appThemes: appThemes),
    ),
  );
}

Replace your MaterialApp or MaterialApp.router with AccessibleMaterialApp or AccessibleMaterialApp.router:

  @override
  Widget build(BuildContext context) => AccessibleMaterialApp.router(
    title: 'Accessibility Example',
    routerConfig: _router,
    // [appThemes] is the [AppThemes] class provided in the main function
    theme: appThemes.lightTheme,
    darkTheme: appThemes.darkTheme,
    // ... other MaterialApp properties
  );

If you want to use the CupertinoApp or WidgetsApp variants check the AccessibleMaterialApp Widget to find out how to create an accessible version of them.

Adding accessibility features #

You can add a complete accessibility settings panel as a body of a Scaffold using the AccessibilitySettings Widget:

 const Scaffold(body: AccessibilitySettings()),
Accessibility settings section - top view Accessibility settings section - middle view Accessibility settings section - bottom view

If you have a subtree with complex animations, consider adding a Widget that reacts to the effects allowed setting, to manage whether or not use the animations:

const EffectsSettingListenableBuilder(
  builder: (context, effectsEnabled, child) => // your widget based on the effectsEnabled value
)

By default all pages transitions of the application will listen to the current effects setting, removing the transition animations if the effects are disabled.

Custom behavior #

This section is intended only for users who want to have more control over the package.

App initialization

For more granular control of the app initialization you can use ThemeSettingsBuilder instead of the premade AccessibleMaterialApp.

  @override
  Widget build(BuildContext context) => ThemeSettingsBuilder(
    builder: (
      context,
      themeMode,
      colorSettings,
      textSettings, {
      required effectsEnabled,
    }) {
      // your custom logic to create theme data
      // instead of AccessibleThemeData...
      return MaterialApp(),
    },
  );

Customizing the accessibility settings

The AccessibilitySettings Widget uses the recommended configuration by default. You can customise it by passing a custom AccessibilitySettingsConfiguration, but be aware that all Text Widgets of your application will NOT be affected by the TextAlign setting. If you want to use the TextAlign settings you should use the AccessibleText Widget instead.

// Instead of const Text('Hello World')
const AccessibleText('Hello World')

Custom UI of the accessibility settings

To add your custom UI of the accessibility settings use only the following providers:

  • AccessibilitySettingsInherited to access and modify the current state of the accessibility settings
  • SharedPreferencesInherited to access and modify the current state of local storage settings

Check the /example/with_custom_ui/ folder for a complete implementation example showing how to add your custom UI to change accessibility settings.

Example #

Check the /example folder for a complete implementation example showing how to integrate accessibility features into your Flutter application.

2
likes
160
points
234
downloads
screenshot

Publisher

verified publisherrubencesario.com

Weekly Downloads

An all-in-one solution to enhance your project with accessibility features.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#accessibility #a11y #utils #utility #theme

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_localizations, intl, shared_preferences

More

Packages that depend on accessibility