Skip to content

Commit a75271f

Browse files
committed
Update Condition Required Value
- Update Condition to respect type nullability. - Require Condition value.
1 parent b6fad43 commit a75271f

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

lib/responsive_value.dart

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,40 +153,48 @@ class Condition<T> {
153153
final int? breakpointEnd;
154154
final String? name;
155155
final Conditional? condition;
156-
final T? value;
157-
final T? landscapeValue;
156+
final T value;
157+
late T landscapeValue;
158158

159-
const Condition._(
159+
Condition._(
160160
{this.breakpointStart,
161161
this.breakpointEnd,
162162
this.name,
163163
this.condition,
164-
this.value,
165-
this.landscapeValue})
166-
: assert(breakpointStart != null || name != null),
164+
required this.value,
165+
T? landscapeValue})
166+
: landscapeValue = (landscapeValue ?? value),
167+
assert(breakpointStart != null || name != null),
167168
assert((condition == Conditional.EQUALS) ? name != null : true);
168169

169-
const Condition.equals({required this.name, this.value, this.landscapeValue})
170-
: breakpointStart = null,
170+
Condition.equals({required this.name, required this.value, T? landscapeValue})
171+
: landscapeValue = (landscapeValue ?? value),
172+
breakpointStart = null,
171173
breakpointEnd = null,
172174
condition = Conditional.EQUALS;
173175

174-
const Condition.largerThan(
175-
{int? breakpoint, this.name, this.value, this.landscapeValue})
176-
: breakpointStart = breakpoint,
176+
Condition.largerThan(
177+
{int? breakpoint, this.name, required this.value, T? landscapeValue})
178+
: landscapeValue = (landscapeValue ?? value),
179+
breakpointStart = breakpoint,
177180
breakpointEnd = breakpoint,
178181
condition = Conditional.LARGER_THAN;
179182

180-
const Condition.smallerThan(
181-
{int? breakpoint, this.name, this.value, this.landscapeValue})
182-
: breakpointStart = breakpoint,
183+
Condition.smallerThan(
184+
{int? breakpoint, this.name, required this.value, T? landscapeValue})
185+
: landscapeValue = (landscapeValue ?? value),
186+
breakpointStart = breakpoint,
183187
breakpointEnd = breakpoint,
184188
condition = Conditional.SMALLER_THAN;
185189

186190
/// Conditional when screen width is between [start] and [end] inclusive.
187-
const Condition.between(
188-
{required int? start, required int? end, this.value, this.landscapeValue})
189-
: breakpointStart = start,
191+
Condition.between(
192+
{required int? start,
193+
required int? end,
194+
required this.value,
195+
T? landscapeValue})
196+
: landscapeValue = (landscapeValue ?? value),
197+
breakpointStart = start,
190198
breakpointEnd = end,
191199
name = null,
192200
condition = Conditional.BETWEEN;

0 commit comments

Comments
 (0)