animated_toggle_switch 0.7.0 copy "animated_toggle_switch: ^0.7.0" to clipboard
animated_toggle_switch: ^0.7.0 copied to clipboard

Simple and animated switch with multiple choices and smooth loading animation. It's a good alternative if you don't want to use something like a dropdown menu.

AnimatedToggleSwitch #

pub.dev github likes popularity pub points license

buy me a coffee

If you like this package, please leave a like there on pub.dev and star on GitHub. #

Simple and animated switch with multiple choices and smooth loading animation. It's an easy way if you don't want to use something like a DropDownMenuButton.
LTR and RTL are both supported.
Switches without an (initial) selection are also possible.
Most builder arguments of AnimatedToggleSwitch have a standard and a custom version. This ensures that you can get started easily and still customize a lot if necessary.

For a slider with a similar look, you can check out action_slider.

Example Usage #

usage

Examples #

AnimatedToggleSwitch.dual()
animated_toggle_switch_example_dual
AnimatedToggleSwitch.dual() with loading animation
animated_toggle_switch_example_dual_loading

AnimatedToggleSwitch.rolling()
animated_toggle_switch_example_1
AnimatedToggleSwitch.rolling() with no initial selection
animated_toggle_switch_example_unlisted_value
AnimatedToggleSwitch.rolling() with loading animation
animated_toggle_switch_example_rolling_loading

Modified AnimatedToggleSwitch.rolling()
animated_toggle_switch_example_2
animated_toggle_switch_example_3
animated_toggle_switch_example_gradient

You can build any other switch with CustomAnimatedToggleSwitch()
animated_toggle_switch_example_custom_1

AnimatedToggleSwitch.size()
animated_toggle_switch_example_4
AnimatedToggleSwitch.size() with loading animation
animated_toggle_switch_example_size_loading

Modified AnimatedToggleSwitch.size()
animated_toggle_switch_example_5

AnimatedToggleSwitch.size() with custom rolling animation
animated_toggle_switch_example_6

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

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,
  ... // many more parameters available
)

Simple rolling animation with loading #

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
)

Simple rolling animation with 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)
)

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(
  current: value,
  values: [0, 1, 2, 3],
  iconOpacity: 0.2,
  indicatorSize: Size.fromWidth(100),
  iconBuilder: (value, size) {
    IconData data = Icons.access_time_rounded;
    if (value.isEven) data = Icons.cancel;
    return Icon(data, size: min(size.width, size.height));
  },
  borderColor: value.isEven ? Colors.blue : Colors.red,
  colorBuilder: (i) => i.isEven ? Colors.amber : Colors.red,
  onChanged: (i) => setState(() => value = i),
)

Self-made rolling animation (with foregroundIndicatorIconBuilder) #

AnimatedToggleSwitch<int>.size(
  value: value,
  values: [0, 1, 2, 3],
  iconOpacity: 1.0,
  indicatorSize: 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))
      ]),
    );
  },
  selectedIconSize: Size.square(20),
  iconSize: Size.square(20),
  iconBuilder: iconBuilder,
  colorBuilder: (i) => i.isEven ? Colors.green : Colors.tealAccent,
  onChanged: (i) => setState(() => value = i),
  borderRadius: BorderRadius.circular(8.0),
  borderColor: Colors.red,
),
581
likes
0
pub points
98%
popularity

Publisher

verified publishersplashbyte.dev

Simple and animated switch with multiple choices and smooth loading animation. It's a good alternative if you don't want to use something like a dropdown menu.

Repository (GitHub)
View/report issues

Funding

Consider supporting this project:

buymeacoffee.com
ko-fi.com

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on animated_toggle_switch