@@ -38,11 +38,75 @@ enum FItemDivider {
38
38
none,
39
39
}
40
40
41
- /// An [FItemData ] is used to provide data about the item's position in the current nesting level, i.e. [FTileGroup] .
41
+ /// An [FInheritedItemData ] is used to provide data about the item's position in the current nesting level, i.e. [FTileGroup] .
42
42
///
43
43
/// Users that wish to create their own custom group should pass additional data to the children using a separate
44
44
/// inherited widget.
45
- final class FItemData extends InheritedWidget {
45
+ final class FInheritedItemData extends InheritedWidget {
46
+ /// Returns the [FItemData] in the given [context] .
47
+ static FItemData ? maybeOf (BuildContext context) =>
48
+ context.dependOnInheritedWidgetOfExactType <FInheritedItemData >()? .data;
49
+
50
+ /// The item's properties.
51
+ final FItemData ? data;
52
+
53
+ /// Creates a [FInheritedItemData] .
54
+ const FInheritedItemData ({required super .child, this .data, super .key});
55
+
56
+ /// Creates a [FInheritedItemData] that merges the given fields with the current [FInheritedItemData] .
57
+ static Widget merge ({
58
+ required bool last,
59
+ required Widget child,
60
+ FItemStyle ? style,
61
+ double ? spacing,
62
+ FItemDivider ? divider,
63
+ FWidgetStateMap <Color >? dividerColor,
64
+ double ? dividerWidth,
65
+ bool ? enabled,
66
+ int ? index,
67
+ }) => Builder (
68
+ builder: (context) {
69
+ final parent = maybeOf (context);
70
+ final globalLast = last && (parent? .globalLast ?? true );
71
+
72
+ return FInheritedItemData (
73
+ data: FItemData (
74
+ style: style ?? parent? .style,
75
+ spacing: max (spacing ?? 0 , parent? .spacing ?? 0 ),
76
+ dividerColor: dividerColor ?? parent? .dividerColor ?? FWidgetStateMap .all (Colors .transparent),
77
+ dividerWidth: dividerWidth ?? parent? .dividerWidth ?? 0 ,
78
+ divider: switch ((last, globalLast)) {
79
+ // The first/middle items of a group.
80
+ (false , false ) => divider ?? FItemDivider .none,
81
+ // Last of a group which itself isn't the last.
82
+ // propagatedLast can only be false if parent?.last is false since last must always be true.
83
+ // Hence, parent!.divider can never be null.
84
+ (true , false ) => parent! .divider,
85
+ // The last item in the last group.
86
+ (_, true ) => FItemDivider .none,
87
+ },
88
+ enabled: enabled ?? parent? .enabled ?? true ,
89
+ index: index ?? parent? .index ?? 0 ,
90
+ last: last,
91
+ globalLast: globalLast,
92
+ ),
93
+ child: child,
94
+ );
95
+ },
96
+ );
97
+
98
+ @override
99
+ bool updateShouldNotify (FInheritedItemData old) => data != old.data;
100
+
101
+ @override
102
+ void debugFillProperties (DiagnosticPropertiesBuilder properties) {
103
+ super .debugFillProperties (properties);
104
+ properties.add (DiagnosticsProperty ('data' , data));
105
+ }
106
+ }
107
+
108
+ /// The item's data.
109
+ final class FItemData with Diagnosticable {
46
110
/// The item's style.
47
111
final FItemStyle ? style;
48
112
@@ -70,91 +134,19 @@ final class FItemData extends InheritedWidget {
70
134
/// True if the item is the last item across all levels.
71
135
final bool globalLast;
72
136
73
- /// Creates a [FItemData] .
137
+ /// Creates a new [FItemData] .
74
138
const FItemData ({
75
- required this .style,
76
- required this .spacing,
77
- required this .dividerColor,
78
- required this .dividerWidth,
79
- required this .divider,
80
- required this .enabled,
81
- required this .index,
82
- required this .last,
83
- required this .globalLast,
84
- required super .child,
85
- super .key,
139
+ this .style,
140
+ this .spacing = 0 ,
141
+ this .dividerColor = const FWidgetStateMap ({WidgetState .any: Colors .transparent}),
142
+ this .dividerWidth = 0 ,
143
+ this .divider = FItemDivider .none,
144
+ this .enabled = true ,
145
+ this .index = 0 ,
146
+ this .last = true ,
147
+ this .globalLast = true ,
86
148
});
87
149
88
- /// Creates a [FItemData] that merges the given fields with the current [FItemData] .
89
- static Widget merge ({
90
- required bool last,
91
- required Widget child,
92
- FItemStyle ? style,
93
- double ? spacing,
94
- FItemDivider ? divider,
95
- FWidgetStateMap <Color >? dividerColor,
96
- double ? dividerWidth,
97
- bool ? enabled,
98
- int ? index,
99
- }) => Builder (
100
- builder: (context) {
101
- final parent = context.dependOnInheritedWidgetOfExactType <FItemData >();
102
- final globalLast = last && (parent? .globalLast ?? true );
103
-
104
- return FItemData (
105
- style: style ?? parent? .style,
106
- spacing: max (spacing ?? 0 , parent? .spacing ?? 0 ),
107
- dividerColor: dividerColor ?? parent? .dividerColor ?? FWidgetStateMap .all (Colors .transparent),
108
- dividerWidth: dividerWidth ?? parent? .dividerWidth ?? 0 ,
109
- divider: switch ((last, globalLast)) {
110
- // The first/middle items of a group.
111
- (false , false ) => divider ?? FItemDivider .none,
112
- // Last of a group which itself isn't the last.
113
- // propagatedLast can only be false if parent?.last is false since last must always be true.
114
- // Hence, parent!.divider can never be null.
115
- (true , false ) => parent! .divider,
116
- // The last item in the last group.
117
- (_, true ) => FItemDivider .none,
118
- },
119
- enabled: enabled ?? parent? .enabled ?? true ,
120
- index: index ?? parent? .index ?? 0 ,
121
- last: last,
122
- globalLast: globalLast,
123
- child: child,
124
- );
125
- },
126
- );
127
-
128
- /// Returns the [FItemData] in the given [context] .
129
- static FItemData ? maybeOf (BuildContext context) => context.dependOnInheritedWidgetOfExactType <FItemData >();
130
-
131
- /// Returns the [FItemData] in the given [context] , or a default [FItemData] if none is found.
132
- factory FItemData .of (BuildContext context) =>
133
- maybeOf (context) ??
134
- FItemData (
135
- style: null ,
136
- spacing: 0 ,
137
- dividerColor: FWidgetStateMap .all (Colors .transparent),
138
- dividerWidth: 0 ,
139
- divider: FItemDivider .none,
140
- enabled: true ,
141
- index: 0 ,
142
- last: true ,
143
- globalLast: true ,
144
- child: const SizedBox (),
145
- );
146
-
147
- @override
148
- bool updateShouldNotify (FItemData old) =>
149
- style != old.style ||
150
- dividerColor != old.dividerColor ||
151
- dividerWidth != old.dividerWidth ||
152
- divider != old.divider ||
153
- enabled != old.enabled ||
154
- index != old.index ||
155
- last != old.last ||
156
- globalLast != old.globalLast;
157
-
158
150
@override
159
151
void debugFillProperties (DiagnosticPropertiesBuilder properties) {
160
152
super .debugFillProperties (properties);
@@ -169,4 +161,23 @@ final class FItemData extends InheritedWidget {
169
161
..add (FlagProperty ('last' , value: last, ifTrue: 'last' ))
170
162
..add (FlagProperty ('globalLast' , value: globalLast, ifTrue: 'globalLast' ));
171
163
}
164
+
165
+ @override
166
+ bool operator == (Object other) =>
167
+ identical (this , other) ||
168
+ other is FItemData &&
169
+ runtimeType == other.runtimeType &&
170
+ style == other.style &&
171
+ spacing == other.spacing &&
172
+ dividerColor == other.dividerColor &&
173
+ dividerWidth == other.dividerWidth &&
174
+ divider == other.divider &&
175
+ enabled == other.enabled &&
176
+ index == other.index &&
177
+ last == other.last &&
178
+ globalLast == other.globalLast;
179
+
180
+ @override
181
+ int get hashCode =>
182
+ Object .hash (style, spacing, dividerColor, dividerWidth, divider, enabled, index, last, globalLast);
172
183
}
0 commit comments