binding.dart 1.68 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:ui' as ui show AccessibilityFeatures, window;

import 'package:flutter/foundation.dart';

9
export 'dart:ui' show AccessibilityFeatures;
10 11 12

/// The glue between the semantics layer and the Flutter engine.
// TODO(jonahwilliams): move the remaining semantic related bindings here.
13
class SemanticsBinding extends BindingBase {
14 15 16 17 18 19 20 21 22 23 24 25
  // This class is intended to be used as a mixin, and should not be
  // extended directly.
  factory SemanticsBinding._() => null;

  /// The current [SemanticsBinding], if one has been created.
  static SemanticsBinding get instance => _instance;
  static SemanticsBinding _instance;

  @override
  void initInstances() {
    super.initInstances();
    _instance = this;
26
    _accessibilityFeatures = new ValueNotifier<ui.AccessibilityFeatures>(ui.window.accessibilityFeatures);
27 28 29 30 31 32 33
  }

  /// Called when the platform accessibility features change.
  ///
  /// See [Window.onAccessibilityFeaturesChanged].
  @protected
  void handleAccessibilityFeaturesChanged() {
34
    _accessibilityFeatures.value = ui.window.accessibilityFeatures;
35 36 37 38 39 40 41 42 43
  }

  /// The currently active set of [AccessibilityFeatures].
  ///
  /// This is initialized the first time [runApp] is called and updated whenever
  /// a flag is changed.
  ///
  /// To listen to changes to accessibility features, create a
  /// [WidgetsBindingObserver] and listen to [didChangeAccessibilityFeatures].
44 45
  ValueListenable<ui.AccessibilityFeatures> get accessibilityFeatures => _accessibilityFeatures;
  ValueNotifier<ui.AccessibilityFeatures> _accessibilityFeatures;
46
}