Skip to content

Commit 9cf7495

Browse files
committed
ResponsiveValue Null Type Support
- Latest Flutter and Dart allows nullable types to flow through correctly. Hooray!
1 parent 52b066d commit 9cf7495

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

lib/responsive_value.dart

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'responsive_framework.dart';
1616
/// No validation is performed on [Condition]s so
1717
/// valid conditions must be passed.
1818
class ResponsiveValue<T> {
19-
T? value;
19+
late T value;
2020
final T? defaultValue;
2121
final List<Condition<T>> conditionalValues;
2222

@@ -44,7 +44,7 @@ class ResponsiveValue<T> {
4444
List<Condition> conditions = [];
4545
conditions.addAll(conditionalValues);
4646
// Get visible value from active condition.
47-
value = getValue(context, conditions) ?? defaultValue;
47+
value = (getValue(context, conditions) ?? defaultValue) as T;
4848
}
4949

5050
T? getValue(BuildContext context, List<Condition> conditions) {
@@ -153,8 +153,8 @@ class Condition<T> {
153153
final int? breakpointEnd;
154154
final String? name;
155155
final Conditional? condition;
156-
final T value;
157-
late T landscapeValue;
156+
final T? value;
157+
late T? landscapeValue;
158158

159159
Condition._(
160160
{this.breakpointStart,
@@ -167,32 +167,29 @@ class Condition<T> {
167167
assert(breakpointStart != null || name != null),
168168
assert((condition == Conditional.EQUALS) ? name != null : true);
169169

170-
Condition.equals({required this.name, required this.value, T? landscapeValue})
170+
Condition.equals({required this.name, this.value, T? landscapeValue})
171171
: landscapeValue = (landscapeValue ?? value),
172172
breakpointStart = null,
173173
breakpointEnd = null,
174174
condition = Conditional.EQUALS;
175175

176176
Condition.largerThan(
177-
{int? breakpoint, this.name, required this.value, T? landscapeValue})
177+
{int? breakpoint, this.name, this.value, T? landscapeValue})
178178
: landscapeValue = (landscapeValue ?? value),
179179
breakpointStart = breakpoint,
180180
breakpointEnd = breakpoint,
181181
condition = Conditional.LARGER_THAN;
182182

183183
Condition.smallerThan(
184-
{int? breakpoint, this.name, required this.value, T? landscapeValue})
184+
{int? breakpoint, this.name, this.value, T? landscapeValue})
185185
: landscapeValue = (landscapeValue ?? value),
186186
breakpointStart = breakpoint,
187187
breakpointEnd = breakpoint,
188188
condition = Conditional.SMALLER_THAN;
189189

190190
/// Conditional when screen width is between [start] and [end] inclusive.
191191
Condition.between(
192-
{required int? start,
193-
required int? end,
194-
required this.value,
195-
T? landscapeValue})
192+
{required int? start, required int? end, this.value, T? landscapeValue})
196193
: landscapeValue = (landscapeValue ?? value),
197194
breakpointStart = start,
198195
breakpointEnd = end,

0 commit comments

Comments
 (0)