Slider<D> constructor
- SelectionTrigger eventTrigger = SelectionTrigger.tapAndDrag,
- SymbolRenderer? handleRenderer,
- D? initialDomainValue,
- SliderListenerCallback<
D> ? onChangeCallback, - String? roleId,
- bool snapToDatum = false,
- SliderStyle? style,
- int layoutPaintOrder = LayoutViewPaintOrder.slider,
Constructs a Slider.
eventTrigger
sets the type of gesture handled by the slider.
handleRenderer
draws a handle for the slider. Defaults to a rectangle.
initialDomainValue
sets the initial position of the slider in domain
units. The default is the center of the chart.
onChangeCallback
will be called when the position of the slider
changes during a drag event.
roleId
optional custom role ID for the slider. This can be used to allow
multiple Slider behaviors on the same chart. Normally, there can only be
one slider (per event trigger type) on a chart. This setting allows for
configuring multiple independent sliders.
snapToDatum
configures the slider to snap snap onto the nearest datum
(by domain distance) when dragged. By default, the slider can be
positioned anywhere along the domain axis.
style
configures the color and sizing of the slider line and handle.
layoutPaintOrder
configures the order in which the behavior should be
painted. This value should be relative to LayoutPaintViewOrder.slider.
(e.g. LayoutViewPaintOrder.slider + 1).
Implementation
Slider(
{this.eventTrigger = SelectionTrigger.tapAndDrag,
SymbolRenderer? handleRenderer,
D? initialDomainValue,
SliderListenerCallback<D>? onChangeCallback,
String? roleId,
this.snapToDatum = false,
SliderStyle? style,
this.layoutPaintOrder = LayoutViewPaintOrder.slider})
: _handleRenderer = handleRenderer ?? RectSymbolRenderer(),
_roleId = roleId ?? '',
_style = style ?? SliderStyle(),
_domainValue = initialDomainValue {
if (_domainValue != null) {
_dragStateToFireOnPostRender = SliderListenerDragState.initial;
}
// Setup the appropriate gesture listening.
switch (eventTrigger) {
case SelectionTrigger.tapAndDrag:
_gestureListener = GestureListener(
onTapTest: _onTapTest,
onTap: _onSelect,
onDragStart: _onSelect,
onDragUpdate: _onSelect,
onDragEnd: _onDragEnd);
break;
case SelectionTrigger.pressHold:
_gestureListener = GestureListener(
onTapTest: _onTapTest,
onLongPress: _onSelect,
onDragStart: _onSelect,
onDragUpdate: _onSelect,
onDragEnd: _onDragEnd);
break;
case SelectionTrigger.longPressHold:
_gestureListener = GestureListener(
onTapTest: _onTapTest,
onLongPress: _onLongPressSelect,
onDragStart: _onSelect,
onDragUpdate: _onSelect,
onDragEnd: _onDragEnd);
break;
default:
throw ArgumentError('Slider does not support the event trigger '
'"$eventTrigger"');
}
// Set up chart draw cycle listeners.
_lifecycleListener = LifecycleListener<D>(
onData: _setInitialDragState,
onAxisConfigured: _updateViewData,
onPostrender: _fireChangeEvent,
);
// Set up slider event listeners.
_sliderEventListener = SliderEventListener<D>(onChange: onChangeCallback);
}