-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicon_theme.dart
91 lines (81 loc) · 2.91 KB
/
icon_theme.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2014 The Flutter 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 'package:flutter/foundation.dart';
import 'basic.dart';
import 'framework.dart';
import 'icon_theme_data.dart';
import 'inherited_theme.dart';
/// Controls the default color, opacity, and size of icons in a widget subtree.
///
/// The icon theme is honored by [Icon] and [ImageIcon] widgets.
class IconTheme extends InheritedTheme {
/// Creates an icon theme that controls the color, opacity, and size of
/// descendant widgets.
///
/// Both [data] and [child] arguments must not be null.
const IconTheme({
Key key,
@required this.data,
@required Widget child,
}) : assert(data != null),
assert(child != null),
super(key: key, child: child);
/// Creates an icon theme that controls the color, opacity, and size of
/// descendant widgets, and merges in the current icon theme, if any.
///
/// The [data] and [child] arguments must not be null.
static Widget merge({
Key key,
@required IconThemeData data,
@required Widget child,
}) {
return Builder(
builder: (BuildContext context) {
return IconTheme(
key: key,
data: _getInheritedIconThemeData(context).merge(data),
child: child,
);
},
);
}
/// The color, opacity, and size to use for icons in this subtree.
final IconThemeData data;
/// The data from the closest instance of this class that encloses the given
/// context.
///
/// Defaults to the current [ThemeData.iconTheme].
///
/// Typical usage is as follows:
///
/// ```dart
/// IconThemeData theme = IconTheme.of(context);
/// ```
static IconThemeData of(BuildContext context) {
final IconThemeData iconThemeData = _getInheritedIconThemeData(context).resolve(context);
return iconThemeData.isConcrete
? iconThemeData
: iconThemeData.copyWith(
size: iconThemeData.size ?? const IconThemeData.fallback().size,
color: iconThemeData.color ?? const IconThemeData.fallback().color,
opacity: iconThemeData.opacity ?? const IconThemeData.fallback().opacity,
);
}
static IconThemeData _getInheritedIconThemeData(BuildContext context) {
final IconTheme iconTheme = context.dependOnInheritedWidgetOfExactType<IconTheme>();
return iconTheme?.data ?? const IconThemeData.fallback();
}
@override
bool updateShouldNotify(IconTheme oldWidget) => data != oldWidget.data;
@override
Widget wrap(BuildContext context, Widget child) {
final IconTheme iconTheme = context.findAncestorWidgetOfExactType<IconTheme>();
return identical(this, iconTheme) ? child : IconTheme(data: data, child: child);
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
data.debugFillProperties(properties);
}
}