Skip to content

Commit f9e911b

Browse files
committed
Updated opacity to ensure double value
1 parent b64d8cd commit f9e911b

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

modules/ensemble/lib/framework/widget/widget.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ abstract class EWidgetState<W extends HasController>
100100
rtn = AnimatedOpacity(
101101
// If visible, apply opacity if specified, else default to 1
102102
opacity: widgetController.visible != false
103-
? (Utils.getValidOpacity(widgetController.opacity ?? 1) ?? 1)
103+
? (Utils.optionalDouble(widgetController.opacity ?? 1, min: 0, max: 1.0) ?? 1)
104104
: 0,
105105
duration: widgetController.visibilityTransitionDuration!,
106106
child: rtn);
@@ -116,7 +116,7 @@ abstract class EWidgetState<W extends HasController>
116116
if (widgetController.visibilityTransitionDuration == null &&
117117
widgetController.opacity != null) {
118118
rtn = Opacity(
119-
opacity: Utils.getValidOpacity(widgetController.opacity!) ?? 1,
119+
opacity: Utils.optionalDouble(widgetController.opacity!, min: 0, max: 1.0) ?? 1.0,
120120
child: rtn,
121121
);
122122
}

modules/ensemble/lib/util/utils.dart

-7
Original file line numberDiff line numberDiff line change
@@ -694,13 +694,6 @@ class Utils {
694694
return textAlign;
695695
}
696696

697-
static double? getValidOpacity(double opacity) {
698-
if (opacity < 0 || opacity > 1) {
699-
return 1;
700-
} else {
701-
return opacity;
702-
}
703-
}
704697

705698
static Curve? getCurve(String? curveType) {
706699
Curve? curve;

modules/ensemble/lib/widget/helpers/controllers.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ abstract class WidgetController extends Controller with HasStyles {
261261
'flex': (value) => flex = Utils.optionalInt(value, min: 1),
262262
'expanded': (value) => expanded = Utils.getBool(value, fallback: false),
263263
'visible': (value) => visible = Utils.getBool(value, fallback: true),
264-
'opacity': (value) => opacity = Utils.getValidOpacity(value),
264+
'opacity': (value) => opacity = Utils.optionalDouble(value, min: 0, max: 1),
265265
'visibilityTransitionDuration': (value) =>
266266
visibilityTransitionDuration = Utils.getDuration(value),
267267
'elevation': (value) =>
@@ -487,7 +487,7 @@ abstract class EnsembleWidgetController extends EnsembleController
487487
'flexMode': (value) => flexMode = FlexMode.values.from(value),
488488
'flex': (value) => flex = Utils.optionalInt(value, min: 1),
489489
'visible': (value) => visible = Utils.getBool(value, fallback: true),
490-
'opacity': (value) => opacity = Utils.getValidOpacity(value),
490+
'opacity': (value) => opacity = Utils.optionalDouble(value, min: 0, max: 1),
491491
'visibilityTransitionDuration': (value) =>
492492
visibilityTransitionDuration = Utils.getDuration(value),
493493
'textDirection': (value) => textDirection = Utils.getTextDirection(value),

0 commit comments

Comments
 (0)