Skip to content

Commit 2f1f641

Browse files
committed
Update ResponsiveValue Typing
- Add typing to ResponsiveVisibility and ResponsiveConstraints. - FIX invalid types and null types being passed to ResponsiveVisibility.
1 parent e27c4d6 commit 2f1f641

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/responsive_value.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import 'package:collection/collection.dart' show IterableExtension;
44
import 'package:flutter/widgets.dart';
55

6-
import 'responsive_framework.dart';
6+
import 'responsive_breakpoints.dart';
77

88
/// Conditional values based on the active breakpoint.
99
///
@@ -196,15 +196,15 @@ class Condition<T> {
196196
name = null,
197197
condition = Conditional.BETWEEN;
198198

199-
Condition copyWith({
199+
Condition<T> copyWith({
200200
int? breakpointStart,
201201
int? breakpointEnd,
202202
String? name,
203203
Conditional? condition,
204204
T? value,
205205
T? landscapeValue,
206206
}) =>
207-
Condition._(
207+
Condition<T>._(
208208
breakpointStart: breakpointStart ?? this.breakpointStart,
209209
breakpointEnd: breakpointEnd ?? this.breakpointEnd,
210210
name: name ?? this.name,
@@ -232,8 +232,8 @@ class Condition<T> {
232232
class ResponsiveVisibility extends StatelessWidget {
233233
final Widget child;
234234
final bool visible;
235-
final List<Condition> visibleConditions;
236-
final List<Condition> hiddenConditions;
235+
final List<Condition<bool>> visibleConditions;
236+
final List<Condition<bool>> hiddenConditions;
237237
final Widget replacement;
238238
final bool maintainState;
239239
final bool maintainAnimation;
@@ -258,20 +258,20 @@ class ResponsiveVisibility extends StatelessWidget {
258258
@override
259259
Widget build(BuildContext context) {
260260
// Initialize mutable value holders.
261-
List<Condition> conditions = [];
262-
bool? visibleValue = visible;
261+
List<Condition<bool>> conditions = [];
262+
bool visibleValue = visible;
263263

264264
// Combine Conditions.
265265
conditions.addAll(visibleConditions.map((e) => e.copyWith(value: true)));
266266
conditions.addAll(hiddenConditions.map((e) => e.copyWith(value: false)));
267267
// Get visible value from active condition.
268-
visibleValue = ResponsiveValue(context,
268+
visibleValue = ResponsiveValue<bool>(context,
269269
defaultValue: visibleValue, conditionalValues: conditions)
270270
.value;
271271

272272
return Visibility(
273273
replacement: replacement,
274-
visible: visibleValue!,
274+
visible: visibleValue,
275275
maintainState: maintainState,
276276
maintainAnimation: maintainAnimation,
277277
maintainSize: maintainSize,
@@ -285,7 +285,7 @@ class ResponsiveVisibility extends StatelessWidget {
285285
class ResponsiveConstraints extends StatelessWidget {
286286
final Widget child;
287287
final BoxConstraints? constraint;
288-
final List<Condition> conditionalConstraints;
288+
final List<Condition<BoxConstraints?>> conditionalConstraints;
289289

290290
const ResponsiveConstraints(
291291
{super.key,
@@ -298,7 +298,7 @@ class ResponsiveConstraints extends StatelessWidget {
298298
// Initialize mutable value holders.
299299
BoxConstraints? constraintValue = constraint;
300300
// Get value from active condition.
301-
constraintValue = ResponsiveValue(context,
301+
constraintValue = ResponsiveValue<BoxConstraints?>(context,
302302
defaultValue: constraintValue,
303303
conditionalValues: conditionalConstraints)
304304
.value;

0 commit comments

Comments
 (0)