패키지, 저장소 및 앱 카테고리 검색

animated_toggle_switch 표지
패키지 상세v0.8.7

animated_toggle_switch

완전히 사용자 정의가 가능하고 드래그 가능한 애니메이션 스위치로 여러 선택지와 부드러운 로딩 애니메이션을 제공합니다. 롤링 및 크기 애니메이션용 사전 구축 생성자가 있습니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
7.1만
좋아요
1천
Pub 점수
160

패키지 설치

flutter pub add animated_toggle_switch

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

다양한 선택을 지원하고 부드러운 로딩 애니메이션을 제공하는 완전히 사용자 정의 가능한 드래그 가능한 애니메이션 토글 스위치입니다. 롤링 및 크기 전환을 위한 사전 구축된 생성자를 제공하여 시각적 피드백이 필요한 인터랙티브 UI에 이상적입니다. Android, iOS, Web, macOS, Windows, Linux를 모두 지원하는 크로스플랫폼용으로 설계되었습니다. 직관적인 API와 원활한 통합을 통해 동적이고 반응형 스위치를 통해 사용자 경험을 향상시킵니다.

사용 사례

  • 인터랙티브 설정 패널
  • 시각적 피드백이 있는 폼 컨트롤
  • 사용자 지정 가능한 테마 전환
  • 다이나믹 선택
  • 부드러운 사용자 인터페이스 전환
  • 크로스플랫폼 토글 컴포넌트

주요 기능

  • 드래그 가능한 인터페이스
  • 다중 선택 지원
  • 사전 구축된 롤링 및 크기 애니메이션
  • 완전히 사용자 정의 가능한 디자인
  • 부드러운 로딩 전환
  • 크로스 플랫폼 호환성

적합한 대상

  • 인터랙티브 폼을 개발하는 개발자
  • 동적 스위치를 찾는 UI 디자이너
  • 테마 또는 선호 설정 전환을 필요로 하는 앱
  • 크로스플랫폼 플러터 애플리케이션
  • 시각적 완성도를 강조하는 프로젝트

고려 사항

  • 많은 인스턴스가 있는 경우 성능에 영향을 미칠 수 있습니다
  • 최적의 시각적 외관을 위해 신중한 스타일링이 필요합니다
  • 토글 스타일 상호작용에 제한됨
  • 상호작용이 없는 요소에 적합하지 않습니다
  • 애니메이션의 복잡도는 모바일 기기의 배터리 수명에 영향을 미칠 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

AnimatedToggleSwitch

pub.dev github likes downloads pub points license codecov buy me a coffee

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

usage

Examples

AnimatedToggleSwitch.dual()
animated_toggle_switch_example_dual animated_toggle_switch_example_borderradius_builder animated_toggle_switch_example_gradient

Switch inspired by lite_rolling_switch (made with AnimatedToggleSwitch.dual())
animated_toggle_switch_example_lite_rolling_switch

Switch inspired by toggle_switch (made with AnimatedToggleSwitch.size())
animated_toggle_switch_example_toggle_switch

Switch inspired by crazy-switch (made with CustomAnimatedToggleSwitch())
animated_toggle_switch_example_crazy_switch

Switch inspired by load_switch (made with CustomAnimatedToggleSwitch())
animated_toggle_switch_example_loading_switch

AnimatedToggleSwitch.rolling()
animated_toggle_switch_example_1 animated_toggle_switch_example_2 animated_toggle_switch_example_gradient animated_toggle_switch_example_borderradius_builder_2 animated_toggle_switch_example_rolling_separator

You can build any other switch with CustomAnimatedToggleSwitch()
animated_toggle_switch_example_custom_1

AnimatedToggleSwitch.size()
animated_toggle_switch_example_size animated_toggle_switch_example_size_2

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

animated_toggle_switch_example_rolling_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
)
Nullable selection

animated_toggle_switch_example_unlisted_value
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

animated_toggle_switch_example_vertical
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

animated_toggle_switch_example_size

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)

animated_toggle_switch_example_6

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

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트