Skip to content

Commit

Permalink
Add range slider properties getters
Browse files Browse the repository at this point in the history
  • Loading branch information
rmahmadkhan committed Nov 20, 2024
1 parent 85f5d68 commit d94b59b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ class ThumbStyleComposite extends WidgetCompositeProperty {
Utils.getDouble(payload['elevation'], fallback: 1.0);
composite.pressedElevation =
Utils.getDouble(payload['pressedElevation'], fallback: 2.0);
composite.thumbColor =
Utils.getColor(payload['thumbColor']);
composite.thumbColor = Utils.getColor(payload['thumbColor']);
composite.disabledThumbColor =
Utils.getColor(payload['disabledThumbColor']);
composite.borderWidth =
Expand All @@ -94,14 +93,12 @@ class ThumbStyleComposite extends WidgetCompositeProperty {

@override
Map<String, Function> setters() => {
'radius': (value) =>
radius = Utils.getDouble(value, fallback: 10.0),
'radius': (value) => radius = Utils.getDouble(value, fallback: 10.0),
'elevation': (value) =>
elevation = Utils.getDouble(value, fallback: 1.0),
'pressedElevation': (value) =>
pressedElevation = Utils.getDouble(value, fallback: 2.0),
'thumbColor': (value) =>
thumbColor = Utils.getColor(value),
'thumbColor': (value) => thumbColor = Utils.getColor(value),
'disabledThumbColor': (value) =>
disabledThumbColor = Utils.getColor(value),
'borderWidth': (value) =>
Expand Down Expand Up @@ -132,4 +129,12 @@ class ThumbStyleComposite extends WidgetCompositeProperty {
borderColor: borderColor,
);
}
}

RangeSliderThumbShape getRangeThumbShape() {
return RoundRangeSliderThumbShape(
enabledThumbRadius: radius,
elevation: elevation,
pressedElevation: pressedElevation,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,15 @@ class TrackStyleComposite extends WidgetCompositeProperty {
return RectangularSliderTrackShape();
}
}
}

RangeSliderTrackShape getRangeTrackShape() {
switch (shape) {
case 'rectangular':
return RectangularRangeSliderTrackShape();
case 'circle':
return RoundedRectRangeSliderTrackShape();
default:
return RectangularRangeSliderTrackShape();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ class ValueIndicatorStyleComposite extends WidgetCompositeProperty {
: super(widgetController);

ShowValueIndicator visibility = ShowValueIndicator.onlyForDiscrete;
ValueIndicatorShape shape = ValueIndicatorShape.drop;
ValueIndicatorShape shape = ValueIndicatorShape.drop;
Color? color;
TextStyle? textStyle;

factory ValueIndicatorStyleComposite.from(
ChangeNotifier widgetController, dynamic payload) {
ValueIndicatorStyleComposite composite = ValueIndicatorStyleComposite(widgetController);
ValueIndicatorStyleComposite composite =
ValueIndicatorStyleComposite(widgetController);
if (payload is Map) {
composite.visibility = ShowValueIndicator.values.from(payload['visibility']) ??
ShowValueIndicator.onlyForDiscrete;

composite.shape = ValueIndicatorShape.values.from(payload['shape']) ??
ValueIndicatorShape.drop;

composite.visibility =
ShowValueIndicator.values.from(payload['visibility']) ??
ShowValueIndicator.onlyForDiscrete;

composite.shape = ValueIndicatorShape.values.from(payload['shape']) ??
ValueIndicatorShape.drop;

composite.color = Utils.getColor(payload['color']);
composite.textStyle = Utils.getTextStyle(payload['textStyle']);
}
Expand All @@ -30,12 +32,11 @@ class ValueIndicatorStyleComposite extends WidgetCompositeProperty {

@override
Map<String, Function> setters() => {
'visibility': (value) =>
visibility = ShowValueIndicator.values.from(value) ??
'visibility': (value) => visibility =
ShowValueIndicator.values.from(value) ??
ShowValueIndicator.onlyForDiscrete,
'shape': (value) =>
shape = ValueIndicatorShape.values.from(value) ??
ValueIndicatorShape.drop,
'shape': (value) => shape =
ValueIndicatorShape.values.from(value) ?? ValueIndicatorShape.drop,
'color': (value) => color = Utils.getColor(value),
'textStyle': (value) => textStyle = Utils.getTextStyle(value),
};
Expand All @@ -58,15 +59,22 @@ class ValueIndicatorStyleComposite extends WidgetCompositeProperty {
case ValueIndicatorShape.paddle:
return PaddleSliderValueIndicatorShape();
case ValueIndicatorShape.drop:
return DropSliderValueIndicatorShape();
return DropSliderValueIndicatorShape();
default:
return DropSliderValueIndicatorShape();
}
}

RangeSliderValueIndicatorShape? getRangeIndicatorShape() {
switch (shape) {
case ValueIndicatorShape.rectangular:
return RectangularRangeSliderValueIndicatorShape();
case ValueIndicatorShape.paddle:
return PaddleRangeSliderValueIndicatorShape();
default:
return DropSliderValueIndicatorShape();
return RectangularRangeSliderValueIndicatorShape();
}
}
}

enum ValueIndicatorShape {
drop,
paddle,
rectangular
}
enum ValueIndicatorShape { drop, paddle, rectangular }
6 changes: 6 additions & 0 deletions modules/ensemble/lib/widget/input/slider/slider_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class SliderState extends FormFieldWidgetState<EnsembleSlider> {
widget.controller.valueIndicatorStyle.textStyle,
valueIndicatorShape:
widget.controller.valueIndicatorStyle.getIndicatorShape(),

// Range Slider Properties
rangeValueIndicatorShape:
widget.controller.valueIndicatorStyle.getRangeIndicatorShape(),
rangeThumbShape: widget.controller.thumbStyle.getRangeThumbShape(),
rangeTrackShape: widget.controller.trackStyle.getRangeTrackShape(),
);

return SliderTheme(
Expand Down

0 comments on commit d94b59b

Please sign in to comment.