AnimatedToggleSwitch

pub.dev github likes 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. It's an easy way if you don't want to use something like a DropDownMenuButton.

Example Usage

usage

Example

example

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,
)

Custom with Size Animation

AnimatedToggleSwitch<int>.size(
  current: value,
  values: [0, 1, 2, 3],
  iconOpacity: 0.2,
  indicatorSize: Size.fromWidth(100),
  indicatorType: IndicatorType.rectangle,
  iconBuilder: (i, size, active) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Text('$i'),
        iconBuilder(i, size, active),
      ],
    );
  },
  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(
  current: value,
  values: [0, 1, 2, 3],
  iconOpacity: 1.0,
  indicatorSize: Size.fromWidth(25),
  foregroundIndicatorIconBuilder: (d, indicatorSize) {
    double transitionValue = d - d.floorToDouble();
    return Transform.rotate(
        angle: 2.0 * pi * transitionValue,
        child: Stack(children: [
          Opacity(opacity: 1 - transitionValue, child: iconBuilder(d.floor(), indicatorSize, true)),
          Opacity(opacity: transitionValue, child: iconBuilder(d.ceil(), indicatorSize, true))
        ]));
  },
  selectedIconSize: Size.square(20),
  iconSize: Size.square(20),
  indicatorType: IndicatorType.rectangle,
  iconBuilder: iconBuilder,
  colorBuilder: (i) => i.isEven ? Colors.green : Colors.tealAccent,
  onChanged: (i) => setState(() => value = i),
  borderRadius: BorderRadius.circular(8.0),
  borderColor: Colors.red,
)

Libraries

animated_toggle_switch