Skip to content

Commit

Permalink
Updated opacity to ensure double value
Browse files Browse the repository at this point in the history
  • Loading branch information
mehsaandev committed Feb 27, 2025
1 parent b64d8cd commit f9e911b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
4 changes: 2 additions & 2 deletions modules/ensemble/lib/framework/widget/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ abstract class EWidgetState<W extends HasController>
rtn = AnimatedOpacity(
// If visible, apply opacity if specified, else default to 1
opacity: widgetController.visible != false
? (Utils.getValidOpacity(widgetController.opacity ?? 1) ?? 1)
? (Utils.optionalDouble(widgetController.opacity ?? 1, min: 0, max: 1.0) ?? 1)
: 0,
duration: widgetController.visibilityTransitionDuration!,
child: rtn);
Expand All @@ -116,7 +116,7 @@ abstract class EWidgetState<W extends HasController>
if (widgetController.visibilityTransitionDuration == null &&
widgetController.opacity != null) {
rtn = Opacity(
opacity: Utils.getValidOpacity(widgetController.opacity!) ?? 1,
opacity: Utils.optionalDouble(widgetController.opacity!, min: 0, max: 1.0) ?? 1.0,
child: rtn,
);
}
Expand Down
7 changes: 0 additions & 7 deletions modules/ensemble/lib/util/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -694,13 +694,6 @@ class Utils {
return textAlign;
}

static double? getValidOpacity(double opacity) {
if (opacity < 0 || opacity > 1) {
return 1;
} else {
return opacity;
}
}

static Curve? getCurve(String? curveType) {
Curve? curve;
Expand Down
4 changes: 2 additions & 2 deletions modules/ensemble/lib/widget/helpers/controllers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ abstract class WidgetController extends Controller with HasStyles {
'flex': (value) => flex = Utils.optionalInt(value, min: 1),
'expanded': (value) => expanded = Utils.getBool(value, fallback: false),
'visible': (value) => visible = Utils.getBool(value, fallback: true),
'opacity': (value) => opacity = Utils.getValidOpacity(value),
'opacity': (value) => opacity = Utils.optionalDouble(value, min: 0, max: 1),
'visibilityTransitionDuration': (value) =>
visibilityTransitionDuration = Utils.getDuration(value),
'elevation': (value) =>
Expand Down Expand Up @@ -487,7 +487,7 @@ abstract class EnsembleWidgetController extends EnsembleController
'flexMode': (value) => flexMode = FlexMode.values.from(value),
'flex': (value) => flex = Utils.optionalInt(value, min: 1),
'visible': (value) => visible = Utils.getBool(value, fallback: true),
'opacity': (value) => opacity = Utils.getValidOpacity(value),
'opacity': (value) => opacity = Utils.optionalDouble(value, min: 0, max: 1),
'visibilityTransitionDuration': (value) =>
visibilityTransitionDuration = Utils.getDuration(value),
'textDirection': (value) => textDirection = Utils.getTextDirection(value),
Expand Down

0 comments on commit f9e911b

Please sign in to comment.