animated_toggle_switch
v0.8.7Fully customizable, draggable and animated switch with multiple choices and smooth loading animation. It has prebuilt constructors for rolling and size animations.
Package archive: https://pubdev.letsnova.ru/api/archives/animated_toggle_switch/0.8.7.tar.gz
dart pub add animated_toggle_switchReadme
AnimatedToggleSwitch
If you like this package, please like it on pub.dev and star it on GitHub.
Fully customizable, draggable and animated switch with multiple choices and smooth loading animation. It has prebuilt constructors for rolling and size animations, but it also allows you to create your own switches with CustomAnimatedToggleSwitch.
LTR and RTL are both supported.
Switches without an (initial) selection and vertical switches are also possible.
Most builder arguments of AnimatedToggleSwitch have standard and a custom version. This ensures that you can get started easily and still customize a lot if necessary. There are several options for styling it.
For a slider with a similar look you can check out action_slider.
Example Usage

Examples
AnimatedToggleSwitch.dual()
Switch inspired by lite_rolling_switch (made with AnimatedToggleSwitch.dual())
Switch inspired by toggle_switch (made with AnimatedToggleSwitch.size())
Switch inspired by crazy-switch (made with CustomAnimatedToggleSwitch())
Switch inspired by load_switch (made with CustomAnimatedToggleSwitch())
AnimatedToggleSwitch.rolling()
You can build any other switch with CustomAnimatedToggleSwitch()

AnimatedToggleSwitch.size()
AnimatedToggleSwitch.size() with custom rolling animation

AnimatedToggleSwitch.rolling() with custom indicatorSize, borderRadius and indicatorBorderRadius

Easy Usage
Easy to use and highly customizable.
Simple rolling animation
AnimatedToggleSwitch<int>.rolling(
current: value,
values: [0, 1, 2, 3],
onChanged: (i) => setState(() => value = i),
iconBuilder: iconBuilder,
// iconList: [...], you can use iconBuilder, customIconBuilder or iconList
style: ToggleStyle(...), // optional style settings
... // many more parameters available
)
Styling
Styling with constructor
style, styleBuilder, customStyleBuilder and styleList can be used to style an AnimatedToggleSwitch.
For the general look of the switch, you can use style.
For parameters that should change with the selection, you can use styleBuilder or styleList.
If you need additional parameters, you can use customStyleBuilder.
AnimatedToggleSwitch<int>.rolling(
...
style: ToggleStyle(backgroundColor: Colors.red), // backgroundColor is set independently of the current selection
styleBuilder: (value) => ToggleStyle(indicatorColor: value.isEven ? Colors.yellow : Colors.green)), // indicatorColor changes and animates its value with the selection
...
)
Styling with Theme
You can also add ToggleStyle to ThemeData.
This overwrites the default ToggleStyle values in all AnimatedToggleSwitch widgets in your MaterialApp.
MaterialApp(
theme: ThemeData(..., extensions: [ToggleStyle(...)]),
...
)
After that, you can access this ToggleStyle anywhere in your MaterialApp:
import 'package:animated_toggle_switch/animated_toggle_switch.dart';
...
Theme.of(context).toggleStyle
Loading animation

To use the loading animation, you simply have to return a Future in onChanged or onTap.
You can alternatively control the loading manually with the loading parameter.
Hence, to disable the loading animation, loading: false must be set.
AnimatedToggleSwitch<int>.rolling(
current: value,
values: [0, 1, 2, 3],
onChanged: (i) async {
setState(() => value = i);
await Future.delayed(Duration(seconds: 3));
},
loading: false, // for deactivating loading animation
iconBuilder: iconBuilder,
... // many more parameters available
)
Nullable selection
To use this feature, you simply have to set allowUnlistedValues to true.
AnimatedToggleSwitch<int?>.rolling(
allowUnlistedValues: true,
current: nullableValue, // no selection if nullableValue is not contained in values
values: const [0, 1, 2, 3],
onChanged: (i) => setState(() => nullableValue = i),
iconBuilder: iconBuilder,
indicatorAppearingBuilder: ..., // appearing animation is fully customizable (optional)
)
Vertical switches
You can get a vertical version of any switch by calling vertical() on it.
AnimatedToggleSwitch<int>.rolling(...).vertical()
Fully customizable toggle switch with CustomAnimatedToggleSwitch
CustomAnimatedToggleSwitch<int>(
current: value,
values: [0, 1, 2, 3],
wrapperBuilder: ..., // the builder for the wrapper around the whole switch
iconBuilder: ..., // the builder for the icons
foregroundIndicatorBuilder: ..., // a builder for an indicator in front of the icons
backgroundIndicatorBuilder: ..., // a builder for an indicator behind the icons
... // many more parameters available
)
AnimatedToggleSwitch.size with some settings
AnimatedToggleSwitch<int>.size(
textDirection: TextDirection.rtl,
current: value,
values: const [0, 1, 2, 3],
iconOpacity: 0.2,
indicatorSize: const Size.fromWidth(100),
iconBuilder: iconBuilder,
borderWidth: 4.0,
iconAnimationType: AnimationType.onHover,
style: ToggleStyle(
borderColor: Colors.transparent,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: Colors.black26,
spreadRadius: 1,
blurRadius: 2,
offset: Offset(0, 1.5),
),
],
),
styleBuilder: (i) => ToggleStyle(indicatorColor: colorBuilder(i)),
onChanged: (i) => setState(() => value = i),
)
Self-made rolling animation (with foregroundIndicatorIconBuilder)

AnimatedToggleSwitch<int>.size(
current: value,
values: const [0, 1, 2, 3],
iconOpacity: 1.0,
selectedIconScale: 1.0,
indicatorSize: const Size.fromWidth(25),
foregroundIndicatorIconBuilder: (context, global) {
double pos = global.position;
double transitionValue = pos - pos.floorToDouble();
return Transform.rotate(
angle: 2.0 * pi * transitionValue,
child: Stack(children: [
Opacity(
opacity: 1 - transitionValue,
child: iconBuilder(pos.floor(), global.indicatorSize)),
Opacity(
opacity: transitionValue,
child: iconBuilder(pos.ceil(), global.indicatorSize))
]));
},
iconBuilder: iconBuilder,
style: ToggleStyle(
borderColor: Colors.red,
borderRadius: BorderRadius.circular(8.0),
indicatorBorderRadius: BorderRadius.zero,
),
styleBuilder: (i) => ToggleStyle(indicatorColor: i.isEven == true ? Colors.green : Colors.tealAccent),
onChanged: (i) => setState(() => value = i),
)
Changelog
0.8.7 (2026-01-09)
- fixes #69
0.8.6 (2026-01-09)
- fixes #67
0.8.5 (2025-04-28)
- adds
paddingtoAnimatedToggleSwitch(#65)
0.8.4 (2024-12-18)
- adds option to add
ToggleStyletoThemeDataasThemeExtension - removes usage of deprecated members
0.8.3 (2024-08-12)
- adds support for vertical switches (#61)
0.8.2 (2024-02-26)
- adds
clipBehaviortoAnimatedToggleSwitch(#56)
0.8.1 (2024-02-06)
- adds
indicatorGradienttoToggleStyle(#44) - fixes problems with
backgroundGradientandbackgroundColor(#46) - adds
AnimationType.none - introduces
positionListener(#50) - fixes #51
0.8.0 (2023-09-02)
- adds tests for all
AnimatedToggleSwitchconstructors - adds
separatorBuilder,customSeparatorBuilder,styleandstyleAnimationTypetoAnimatedToggleSwitch - adds
separatorBuildertoCustomAnimatedToggleSwitch - adds
activeto all constructors (#30) - adds
styleBuilderandstyleListtoAnimatedToggleSwitch - adds
iconListtoAnimatedToggleSwitch.size,AnimatedToggleSwitch.sizeByHeight,AnimatedToggleSwitch.rollingandAnimatedToggleSwitch.rollingByHeight - BREAKING: moves many parameters in
AnimatedToggleSwitchtostyle:innerColor(renamed tobackgroundColor)innerGradient(renamed tobackgroundGradient)borderColorindicatorColorborderRadiusindicatorBorderColorindicatorBorderindicatorBorderforegroundBoxShadow(renamed toindicatorBoxShadow)boxShadow
- BREAKING: moves all cursor parameters to
cursors - BREAKING: removes
borderColorBuilderin favor of the newstyleBuilder - BREAKING:
indicatorAnimationTypehandlesToggleStyle.indicatorColor,ToggleStyle.indicatorBorderRadius,ToggleStyle.indicatorBorderandToggleStyle.indicatorBoxShadownow - BREAKING: adds parameter to
onTap(#41) - BREAKING: changes default background color from
ThemeData.scaffoldBackgroundColortoThemeData.colorScheme.surface - BREAKING: renames
diftospacingin all constructors - BREAKING: replaces
transitionTypewithindicatorTransitioninAnimatedToggleSwitch.rolling(),AnimatedToggleSwitch.rollingByHeight()andAnimatedToggleSwitch.dual() - BREAKING: removes
iconSizeandselectedIconSizeinAnimatedToggleSwitchconstructorsrolling(),rollingByHeight(),dual(): new parameterindicatorIconScalecontrols scaling nowsize(),sizeByHeight(): new parameterselectedIconScalecontrols scaling now
0.7.0 (2023-06-19)
- adds possibility that no valid value is selected (by setting
allowUnlistedValuestotrue) - adds new parameters to almost all constructors:
allowUnlistedValues,indicatorAppearingBuilder,indicatorAppearingDuration,indicatorAppearingCurve
0.6.2 (2023-03-09)
- adds screenshot to pubspec.yaml
0.6.1 (2022-12-22)
- adds examples for loading animation to README
0.6.0 (2022-12-22)
- fixes README
- fixes (#28)
- BREAKING: increases minimum SDK to 2.17
- BREAKING: renames
valuetocurrentandpreviousValuetopreviousinDetailedGlobalToggleProperties - BREAKING feature: Adds loading animation to all switches. You can disable it by setting
loadingto false. - adds
innerGradienttoAnimatedToggleSwitch - adds
transitionTypetoAnimatedToggleSwitch.rolling,AnimatedToggleSwitch.rollingByHeightandAnimatedToggleSwitch.dual
0.5.2 (2022-04-22)
- minor performance improvement
- minor fixes
- improves code documentation
- adds
dragCursoranddraggingCursortoCustomAnimatedToggleSwitch - adds
iconsTappable,defaultCursor,dragCursoranddraggingCursortoAnimatedToggleSwitch
0.5.1 (2022-04-21)
- fixes (#20)
0.5.0 (2022-04-20)
- minor performance improvement
- fixes problems with tight constraints
- BREAKING: changes default values of
animationOffsetandclipAnimationinAnimatedToggleSwitch.dual
0.4.0 (2022-04-03)
- minor fixes and performance improvements
- adds
indicatorBorderRadiustoAnimatedToggleSwitch - adds
animationOffset,clipAnimationandopacityAnimationtoAnimatedToggleSwitch.dual - BREAKING: sets default values of
animationOffset,clipAnimationandopacityAnimationinAnimatedToggleSwitch.dual - BREAKING: renames
foregroundBordertoindicatorBorder
0.3.1 (2022-03-23)
- minor fixes
0.3.0 (2022-03-21)
- introduces
CustomAnimatedToggleSwitchfor maximum customizability - most constructors of
AnimatedToggleSwitchhave a standard and a more customizable parameter for their builders now - full support of
TextDirection.rtl - adds animation when dragging the switch
- adds
minTouchTargetSize,dragStartDuration,dragStartCurveandtextDirectiontoAnimatedToggleSwitch - BREAKING:
TextDirectionis taken fromBuildContextby default now!!! - BREAKING: changes parameters and names of some builders
- BREAKING: renames
AnimatedToggleSwitch.byHeighttoAnimatedToggleSwitch.customByHeight - BREAKING: adds default
textMargintoAnimatedToggleSwitch.dual - fixes (#9)
0.2.3 (2022-02-28)
- BREAKING: removes
indicatorType - BREAKING: changes default
innerColor - adds
BoxShadowparameters
0.2.2 (2022-01-27)
- minor performance improvements
0.2.2 (2022-01-27)
- minor changes/fixes
0.2.1 (2021-10-03)
- migrates to Flutter 2.5
- minor changes/fixes
0.2.0 (2021-05-21)
- minor Changes
- fixes
FittingMode.preventHorizontalOverlapping - improves Web support
0.1.3 (2021-03-27)
- updates README.md
0.1.2 (2021-03-27)
- adds
AnimatedToggleSwitch.dual - adds some settings (
AnimationType)
0.1.1 (2021-03-26)
- minor fix
0.1.0 (2021-03-26)
- initial release
