AnimatedToggleSwitch<T extends Object?> class

A class with constructors for different switches. The constructors have sensible default values for their parameters, but can also be customized.

If you want to implement a completely custom switch, you should use CustomAnimatedToggleSwitch, which is used by AnimatedToggleSwitch in the background.

Inheritance

Constructors

AnimatedToggleSwitch.custom({Key? key, required T current, required List<T> values, AnimatedIconBuilder<T>? animatedIconBuilder, Duration animationDuration = const Duration(milliseconds: 500), Curve animationCurve = Curves.easeInOutCirc, Size indicatorSize = const Size(48.0, double.infinity), ChangeCallback<T>? onChanged, double borderWidth = 2.0, ToggleStyle style = const ToggleStyle(), StyleBuilder<T>? styleBuilder, CustomStyleBuilder<T>? customStyleBuilder, List<ToggleStyle>? styleList, Curve iconAnimationCurve = Curves.easeOutBack, Duration? iconAnimationDuration, double iconOpacity = 0.5, double spacing = 0.0, CustomIndicatorBuilder<T>? foregroundIndicatorIconBuilder, double selectedIconOpacity = 1.0, double height = 50.0, AnimationType iconAnimationType = AnimationType.onSelected, AnimationType styleAnimationType = AnimationType.onSelected, AnimationType indicatorAnimationType = AnimationType.onHover, TapCallback<T>? onTap, FittingMode fittingMode = FittingMode.preventHorizontalOverlapping, double minTouchTargetSize = 48.0, TextDirection? textDirection, bool iconsTappable = true, ToggleCursors cursors = const ToggleCursors(), LoadingIconBuilder<T> loadingIconBuilder = _defaultLoadingIconBuilder, bool? loading, Duration? loadingAnimationDuration, Curve? loadingAnimationCurve, bool allowUnlistedValues = false, IndicatorAppearingBuilder indicatorAppearingBuilder = _defaultIndicatorAppearingBuilder, Duration indicatorAppearingDuration = _defaultIndicatorAppearingAnimationDuration, Curve indicatorAppearingCurve = _defaultIndicatorAppearingAnimationCurve, SeparatorBuilder? separatorBuilder, CustomSeparatorBuilder<T>? customSeparatorBuilder, bool active = true, double inactiveOpacity = 0.6, Curve inactiveOpacityCurve = Curves.easeInOut, Duration inactiveOpacityDuration = const Duration(milliseconds: 350), PositionListener<T>? positionListener, Clip clipBehavior = Clip.antiAlias})
Constructor of AnimatedToggleSwitch with all possible settings.
const
AnimatedToggleSwitch.customByHeight({Key? key, double height = 50.0, required T current, required List<T> values, AnimatedIconBuilder<T>? animatedIconBuilder, Duration animationDuration = const Duration(milliseconds: 500), Curve animationCurve = Curves.easeInOutCirc, Size indicatorSize = const Size(1.0, 1.0), ChangeCallback<T>? onChanged, double borderWidth = 2.0, ToggleStyle style = const ToggleStyle(), StyleBuilder<T>? styleBuilder, CustomStyleBuilder<T>? customStyleBuilder, List<ToggleStyle>? styleList, Curve iconAnimationCurve = Curves.easeOutBack, Duration? iconAnimationDuration, double iconOpacity = 0.5, double spacing = 0.0, CustomIndicatorBuilder<T>? foregroundIndicatorIconBuilder, double selectedIconOpacity = 1.0, AnimationType iconAnimationType = AnimationType.onSelected, AnimationType styleAnimationType = AnimationType.onSelected, AnimationType indicatorAnimationType = AnimationType.onHover, TapCallback<T>? onTap, FittingMode fittingMode = FittingMode.preventHorizontalOverlapping, double minTouchTargetSize = 48.0, TextDirection? textDirection, bool iconsTappable = true, ToggleCursors cursors = const ToggleCursors(), LoadingIconBuilder<T> loadingIconBuilder = _defaultLoadingIconBuilder, bool? loading, Duration? loadingAnimationDuration, Curve? loadingAnimationCurve, bool allowUnlistedValues = false, IndicatorAppearingBuilder indicatorAppearingBuilder = _defaultIndicatorAppearingBuilder, Duration indicatorAppearingDuration = _defaultIndicatorAppearingAnimationDuration, Curve indicatorAppearingCurve = _defaultIndicatorAppearingAnimationCurve, SeparatorBuilder? separatorBuilder, CustomSeparatorBuilder<T>? customSeparatorBuilder, bool active = true, double inactiveOpacity = 0.6, Curve inactiveOpacityCurve = Curves.easeInOut, Duration inactiveOpacityDuration = const Duration(milliseconds: 350), PositionListener<T>? positionListener, Clip clipBehavior = Clip.antiAlias})
Special version of AnimatedToggleSwitch.custom.
const
AnimatedToggleSwitch.dual({Key? key, required T current, required T first, required T second, SimpleIconBuilder<T>? iconBuilder, IconBuilder<T>? customIconBuilder, SimpleIconBuilder<T>? textBuilder, AnimatedIconBuilder<T>? customTextBuilder, Duration animationDuration = const Duration(milliseconds: 500), Curve animationCurve = Curves.easeInOutCirc, Size indicatorSize = const Size.fromWidth(46.0), ChangeCallback<T>? onChanged, double borderWidth = 2.0, ToggleStyle style = const ToggleStyle(), StyleBuilder<T>? styleBuilder, CustomStyleBuilder<T>? customStyleBuilder, List<ToggleStyle>? styleList, double spacing = 40.0, double height = 50.0, Duration? iconAnimationDuration = const Duration(milliseconds: 500), Curve iconAnimationCurve = Curves.easeInOut, AnimationType styleAnimationType = AnimationType.onHover, AnimationType indicatorAnimationType = AnimationType.onHover, FittingMode fittingMode = FittingMode.preventHorizontalOverlapping, TapCallback<T>? onTap, double minTouchTargetSize = 48.0, TextDirection? textDirection, ToggleCursors cursors = const ToggleCursors(defaultCursor: SystemMouseCursors.click), EdgeInsetsGeometry textMargin = const EdgeInsets.symmetric(horizontal: 8.0), Offset animationOffset = const Offset(20.0, 0), bool clipAnimation = true, bool opacityAnimation = true, LoadingIconBuilder<T> loadingIconBuilder = _defaultLoadingIconBuilder, bool? loading, Duration? loadingAnimationDuration, Curve? loadingAnimationCurve, ForegroundIndicatorTransition indicatorTransition = const ForegroundIndicatorTransition.rolling(), bool active = true, double inactiveOpacity = 0.6, Curve inactiveOpacityCurve = Curves.easeInOut, Duration inactiveOpacityDuration = const Duration(milliseconds: 350), PositionListener<T>? positionListener, Clip clipBehavior = Clip.antiAlias})
Defining an rolling animation using the foregroundIndicatorIconBuilder of AnimatedToggleSwitch.
AnimatedToggleSwitch.rolling({Key? key, required T current, required List<T> values, SimpleRollingIconBuilder<T>? iconBuilder, RollingIconBuilder<T>? customIconBuilder, List<Widget>? iconList, Duration animationDuration = const Duration(milliseconds: 500), Curve animationCurve = Curves.easeInOutCirc, Size indicatorSize = const Size.fromWidth(46.0), ChangeCallback<T>? onChanged, double borderWidth = 2.0, ToggleStyle style = const ToggleStyle(), StyleBuilder<T>? styleBuilder, CustomStyleBuilder<T>? customStyleBuilder, List<ToggleStyle>? styleList, double iconOpacity = 0.5, double spacing = 0.0, double height = 50.0, AnimationType styleAnimationType = AnimationType.onSelected, AnimationType indicatorAnimationType = AnimationType.onHover, TapCallback<T>? onTap, FittingMode fittingMode = FittingMode.preventHorizontalOverlapping, double minTouchTargetSize = 48.0, TextDirection? textDirection, bool iconsTappable = true, ToggleCursors cursors = const ToggleCursors(), LoadingIconBuilder<T> loadingIconBuilder = _defaultLoadingIconBuilder, bool? loading, Duration? loadingAnimationDuration, Curve? loadingAnimationCurve, ForegroundIndicatorTransition indicatorTransition = const ForegroundIndicatorTransition.rolling(), bool allowUnlistedValues = false, IndicatorAppearingBuilder indicatorAppearingBuilder = _defaultIndicatorAppearingBuilder, Duration indicatorAppearingDuration = _defaultIndicatorAppearingAnimationDuration, Curve indicatorAppearingCurve = _defaultIndicatorAppearingAnimationCurve, SeparatorBuilder? separatorBuilder, CustomSeparatorBuilder<T>? customSeparatorBuilder, bool active = true, double inactiveOpacity = 0.6, Curve inactiveOpacityCurve = Curves.easeInOut, Duration inactiveOpacityDuration = const Duration(milliseconds: 350), PositionListener<T>? positionListener, Clip clipBehavior = Clip.antiAlias, double indicatorIconScale = 1.0})
This constructor defines a rolling animation using the foregroundIndicatorIconBuilder of AnimatedToggleSwitch.
AnimatedToggleSwitch.rollingByHeight({Key? key, double height = 50.0, required T current, required List<T> values, SimpleRollingIconBuilder<T>? iconBuilder, RollingIconBuilder<T>? customIconBuilder, List<Widget>? iconList, Duration animationDuration = const Duration(milliseconds: 500), Curve animationCurve = Curves.easeInOutCirc, Size indicatorSize = const Size.square(1.0), ChangeCallback<T>? onChanged, double borderWidth = 2.0, ToggleStyle style = const ToggleStyle(), StyleBuilder<T>? styleBuilder, CustomStyleBuilder<T>? customStyleBuilder, List<ToggleStyle>? styleList, double iconOpacity = 0.5, double spacing = 0.0, AnimationType styleAnimationType = AnimationType.onSelected, AnimationType indicatorAnimationType = AnimationType.onHover, TapCallback<T>? onTap, FittingMode fittingMode = FittingMode.preventHorizontalOverlapping, double minTouchTargetSize = 48.0, TextDirection? textDirection, bool iconsTappable = true, ToggleCursors cursors = const ToggleCursors(), LoadingIconBuilder<T> loadingIconBuilder = _defaultLoadingIconBuilder, bool? loading, Duration? loadingAnimationDuration, Curve? loadingAnimationCurve, ForegroundIndicatorTransition indicatorTransition = const ForegroundIndicatorTransition.rolling(), bool allowUnlistedValues = false, IndicatorAppearingBuilder indicatorAppearingBuilder = _defaultIndicatorAppearingBuilder, Duration indicatorAppearingDuration = _defaultIndicatorAppearingAnimationDuration, Curve indicatorAppearingCurve = _defaultIndicatorAppearingAnimationCurve, SeparatorBuilder? separatorBuilder, CustomSeparatorBuilder<T>? customSeparatorBuilder, bool active = true, double inactiveOpacity = 0.6, Curve inactiveOpacityCurve = Curves.easeInOut, Duration inactiveOpacityDuration = const Duration(milliseconds: 350), PositionListener<T>? positionListener, Clip clipBehavior = Clip.antiAlias, double indicatorIconScale = 1.0})
Special version of AnimatedToggleSwitch.rolling.
AnimatedToggleSwitch.size({Key? key, required T current, required List<T> values, SimpleIconBuilder<T>? iconBuilder, AnimatedIconBuilder<T>? customIconBuilder, List<Widget>? iconList, Duration animationDuration = const Duration(milliseconds: 500), Curve animationCurve = Curves.easeInOutCirc, Size indicatorSize = const Size.fromWidth(48.0), ChangeCallback<T>? onChanged, double borderWidth = 2.0, ToggleStyle style = const ToggleStyle(), StyleBuilder<T>? styleBuilder, CustomStyleBuilder<T>? customStyleBuilder, List<ToggleStyle>? styleList, double selectedIconScale = sqrt2, Curve iconAnimationCurve = Curves.easeOutBack, Duration? iconAnimationDuration, double iconOpacity = 0.5, double selectedIconOpacity = 1.0, double spacing = 0.0, CustomIndicatorBuilder<T>? foregroundIndicatorIconBuilder, double height = 50.0, AnimationType iconAnimationType = AnimationType.onSelected, AnimationType styleAnimationType = AnimationType.onSelected, AnimationType indicatorAnimationType = AnimationType.onHover, TapCallback<T>? onTap, FittingMode fittingMode = FittingMode.preventHorizontalOverlapping, double minTouchTargetSize = 48.0, TextDirection? textDirection, bool iconsTappable = true, ToggleCursors cursors = const ToggleCursors(), LoadingIconBuilder<T> loadingIconBuilder = _defaultLoadingIconBuilder, bool? loading, Duration? loadingAnimationDuration, Curve? loadingAnimationCurve, bool allowUnlistedValues = false, IndicatorAppearingBuilder indicatorAppearingBuilder = _defaultIndicatorAppearingBuilder, Duration indicatorAppearingDuration = _defaultIndicatorAppearingAnimationDuration, Curve indicatorAppearingCurve = _defaultIndicatorAppearingAnimationCurve, SeparatorBuilder? separatorBuilder, CustomSeparatorBuilder<T>? customSeparatorBuilder, bool active = true, double inactiveOpacity = 0.6, Curve inactiveOpacityCurve = Curves.easeInOut, Duration inactiveOpacityDuration = const Duration(milliseconds: 350), PositionListener<T>? positionListener, Clip clipBehavior = Clip.antiAlias})
Provides an AnimatedToggleSwitch with the standard size animation of the icons.
AnimatedToggleSwitch.sizeByHeight({Key? key, double height = 50.0, required T current, required List<T> values, Duration animationDuration = const Duration(milliseconds: 500), Curve animationCurve = Curves.easeInOutCirc, Size indicatorSize = const Size.square(1.0), SimpleIconBuilder<T>? iconBuilder, AnimatedIconBuilder<T>? customIconBuilder, List<Widget>? iconList, ChangeCallback<T>? onChanged, double borderWidth = 2.0, ToggleStyle style = const ToggleStyle(), StyleBuilder<T>? styleBuilder, CustomStyleBuilder<T>? customStyleBuilder, List<ToggleStyle>? styleList, double selectedIconScale = sqrt2, Curve iconAnimationCurve = Curves.easeOutBack, Duration? iconAnimationDuration, double iconOpacity = 0.5, double spacing = 0.0, CustomIndicatorBuilder<T>? foregroundIndicatorIconBuilder, double selectedIconOpacity = 1.0, AnimationType iconAnimationType = AnimationType.onSelected, AnimationType styleAnimationType = AnimationType.onSelected, AnimationType indicatorAnimationType = AnimationType.onHover, TapCallback<T>? onTap, FittingMode fittingMode = FittingMode.preventHorizontalOverlapping, double minTouchTargetSize = 48.0, TextDirection? textDirection, bool iconsTappable = true, ToggleCursors cursors = const ToggleCursors(), LoadingIconBuilder<T> loadingIconBuilder = _defaultLoadingIconBuilder, bool? loading, Duration? loadingAnimationDuration, Curve? loadingAnimationCurve, bool allowUnlistedValues = false, IndicatorAppearingBuilder indicatorAppearingBuilder = _defaultIndicatorAppearingBuilder, Duration indicatorAppearingDuration = _defaultIndicatorAppearingAnimationDuration, Curve indicatorAppearingCurve = _defaultIndicatorAppearingAnimationCurve, SeparatorBuilder? separatorBuilder, CustomSeparatorBuilder<T>? customSeparatorBuilder, bool active = true, double inactiveOpacity = 0.6, Curve inactiveOpacityCurve = Curves.easeInOut, Duration inactiveOpacityDuration = const Duration(milliseconds: 350), PositionListener<T>? positionListener, Clip clipBehavior = Clip.antiAlias})
Special version of AnimatedToggleSwitch.size.

Properties

active bool
Indicates if the switch is active.
final
allowUnlistedValues bool
Indicates that no error should be thrown if current is not contained in values.
final
animatedIconBuilder AnimatedIconBuilder<T>?
The IconBuilder for all icons with the specified size.
final
animateStyleChanges bool
final
animationCurve Curve
Curve of the motion animation.
final
animationDuration Duration
Duration of the motion animation.
final
borderWidth double
Width of the border of the switch. For deactivating please set this to 0.0.
final
clipBehavior Clip
Clip of the switch wrapper.
final
current → T
The currently selected value. It has to be set at onChanged or whenever for animating to this value.
final
cursors ToggleCursors
The MouseCursor settings for this switch.
final
customSeparatorBuilder CustomSeparatorBuilder<T>?
Builder for divider or other separators between the icons. Consider using separatorBuilder for a simpler builder function.
final
customStyleBuilder CustomStyleBuilder<T>?
Custom builder for the style of the indicator.
final
fittingMode FittingMode
The FittingMode of the switch.
final
foregroundIndicatorIconBuilder CustomIndicatorBuilder<T>?
If null, the indicator is behind the icons. Otherwise an icon is in the indicator and is built using this function.
final
hashCode int
The hash code for this object.
no setterinherited
height double
Total height of the widget.
final
iconAnimationCurve Curve
iconAnimationCurve defines the Duration of the Animation built in animatedIconBuilder. In some constructors this is the Curve of the size animation.
final
iconAnimationDuration Duration?
If null, animationDuration is taken.
final
iconAnimationType AnimationType
The AnimationType for the animatedIconBuilder.
final
iconOpacity double
Opacity for the icons.
final
iconsTappable bool
Indicates if onChanged is called when an icon is tapped. If false the user can change the value only by dragging the indicator.
final
inactiveOpacity double
Opacity of the switch when active is set to false.
final
inactiveOpacityCurve Curve
Curve of the animation when getting inactive.
final
inactiveOpacityDuration Duration
Duration of the animation when getting inactive.
final
indicatorAnimationType AnimationType
The AnimationType for ToggleStyle.indicatorColor, ToggleStyle.indicatorGradient, ToggleStyle.indicatorBorderRadius, ToggleStyle.indicatorBorder and ToggleStyle.indicatorBoxShadow
final
indicatorAppearingBuilder IndicatorAppearingBuilder
Custom builder for the appearing animation of the indicator.
final
indicatorAppearingCurve Curve
Curve of the appearing animation.
final
indicatorAppearingDuration Duration
Duration of the appearing animation.
final
indicatorSize Size
Size of the indicator.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
loading bool?
Indicates if the switch is currently loading.
final
loadingAnimationCurve Curve?
Curve of the loading animation.
final
loadingAnimationDuration Duration?
Duration of the loading animation.
final
loadingIconBuilder LoadingIconBuilder<T>
A builder for the loading icon.
final
minTouchTargetSize double
The minimum size of the indicator's hitbox.
final
onChanged ChangeCallback<T>?
Callback for selecting a new value. The new current should be set here.
final
onTap TapCallback<T>?
Callback for tapping anywhere on the widget.
final
positionListener PositionListener<T>?
Listener for the current position and ToggleMode of the indicator.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selectedIconOpacity double
Opacity for the currently selected icon.
final
separatorBuilder SeparatorBuilder?
Builder for divider or other separators between the icons. Consider using customSeparatorBuilder for maximum customizability.
final
spacing double
Space between adjacent icons.
final
style ToggleStyle
The default style of this switch.
final
styleAnimationType AnimationType
The AnimationType for styleBuilder.
final
styleBuilder StyleBuilder<T>?
Builder for the style of the indicator depending on the current value.
final
styleList List<ToggleStyle>?
List of the styles for all values.
final
textDirection TextDirection?
The direction in which the icons are arranged.
final
values List<T>
All possible values.
final

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited