locale_query.dart 1.05 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 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 'framework.dart';

7
/// Superclass for locale-specific data provided by the application.
8 9
class LocaleQueryData { }

10
/// Establishes a subtree in which locale queries resolve to the given data.
11 12 13 14 15 16 17 18 19
class LocaleQuery<T extends LocaleQueryData> extends InheritedWidget {
  LocaleQuery({
    Key key,
    this.data,
    Widget child
  }) : super(key: key, child: child) {
    assert(child != null);
  }

20
  /// The locale data for this subtree.
21 22
  final T data;

23
  /// The data from the closest instance of this class that encloses the given context.
24
  static LocaleQueryData of(BuildContext context) {
Ian Hickson's avatar
Ian Hickson committed
25
    LocaleQuery query = context.inheritFromWidgetOfExactType(LocaleQuery);
26
    return query?.data;
27 28 29 30 31 32 33 34 35
  }

  bool updateShouldNotify(LocaleQuery old) => data != old.data;

  void debugFillDescription(List<String> description) {
    super.debugFillDescription(description);
    description.add('$data');
  }
}