locale_query.dart 1.26 KB
Newer Older
1 2 3 4
// 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.

5 6
import 'package:meta/meta.dart';

7 8
import 'framework.dart';

9
/// Superclass for locale-specific data provided by the application.
10
class LocaleQueryData { } // TODO(ianh): We need a better type here. This doesn't really make sense.
11

12
/// Establishes a subtree in which locale queries resolve to the given data.
13
class LocaleQuery extends InheritedWidget {
14
  /// Creates a widget that provides [LocaleQueryData] to its descendants.
15 16
  LocaleQuery({
    Key key,
17 18
    @required this.data,
    @required Widget child
19 20 21 22
  }) : super(key: key, child: child) {
    assert(child != null);
  }

23
  /// The locale data for this subtree.
24
  final LocaleQueryData data;
25

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

32
  @override
33 34
  bool updateShouldNotify(LocaleQuery old) => data != old.data;

35
  @override
36 37 38 39 40
  void debugFillDescription(List<String> description) {
    super.debugFillDescription(description);
    description.add('$data');
  }
}