theme.dart 1.06 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
import 'package:flutter/widgets.dart';
6

7 8 9
import 'theme_data.dart';

export 'theme_data.dart' show ThemeData, ThemeBrightness;
10

11
class Theme extends InheritedWidget {
12
  Theme({
13
    Key key,
14 15 16 17 18 19 20 21 22 23 24
    this.data,
    Widget child
  }) : super(key: key, child: child) {
    assert(child != null);
    assert(data != null);
  }

  final ThemeData data;

  static final ThemeData _kFallbackTheme = new ThemeData.fallback();

25 26 27
  /// The data from the closest instance of this class that encloses the given context.
  ///
  /// Defaults to the fallback theme data if none exists.
28
  static ThemeData of(BuildContext context) {
Ian Hickson's avatar
Ian Hickson committed
29
    Theme theme = context.inheritFromWidgetOfExactType(Theme);
30
    return theme?.data ?? _kFallbackTheme;
31 32
  }

33
  bool updateShouldNotify(Theme old) => data != old.data;
Hixie's avatar
Hixie committed
34 35 36 37 38

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