An advanced switch widget, that can be fully customized with size, text, color, radius of corners.

Related tags

Widgets switch flutter
Overview

flutter_advanced_switch

An advanced switch widget, that can be fully customized with size, text, color, radius of corners.

Switch Light Switch Dark
Flutter Advanced Switch Off State Flutter Advanced Switch On State

Getting Started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
    ...
    flutter_advanced_switch: 
   

Import in your project:

import 'package:flutter_advanced_switch/flutter_advanced_switch.dart';

Examples

How to use

// ...
// 1. Create a controller in the state of the StatefulWidget
final _controller = AdvancedSwitchController();

// 2. In case, you want to call setState on switch changes.
// 2.1. Add event listener, for example in the initState() method.
// ...
bool _checked = false;

// ...
@override
void initState() {
  super.initState();

  _controller.addListener(() {
    setState(() {
      if (_controller00.value) {
        _checked = true;
      } else {
        _checked = false;
      }
    });
  });
}

// 3. Add AdvancedSwitch to the build method.
// ...
AdvancedSwitch(
    controller: _controller,
),
// ...

Regular Switch

// ...
final _controller = AdvancedSwitchController();
// ...
AdvancedSwitch(
    controller: _controller,
)
// ...

Customized Switch

// ...
final _controller = AdvancedSwitchController();
// ...
AdvancedSwitch(
    controller: _controller,
    activeColor: Colors.green,
    inactiveColor: Colors.grey,
    activeChild: Text('ON'),
    inactiveChild: Text('OFF'), 
    activeImage: AssetImage('assets/images/on.png'),
    inactiveImage: AssetImage('assets/images/off.png'),
    borderRadius: BorderRadius.all(const Radius.circular(15)),
    width: 50.0,
    height: 30.0,
    enabled: true,
    disabledOpacity: 0.5,
),
// ...

Custom thumb

// ...
final _controller = AdvancedSwitchController();
// ...
AdvancedSwitch(
    controller: _controller,
    thumb: ValueListenableBuilder(
        valueListenable: _controller,
        builder: (_, value, __) {
            return Icon(value
                ? Icons.lightbulb
                : Icons.lightbulb_outline);
        },
    ),
),
// ...

AdvancedSwitch Parameters

Parameter Description Type Default
controller Determines if widget is enabled. AdvancedSwitchController
activeColor Determines current state. Color Colors.green
inactiveColor Determines background color for the active state. Color Colors.grey
activeChild Determines background color for the inactive state. Widget
inactiveChild Determines label for the active state. Widget
activeImage Determines label for the inactive state. ImageProvider
inactiveImage Determines background image for the active state. ImageProvider
borderRadius Determines background image for the inactive state. BorderRadius Radius.circular(15)
width Determines border radius. Double 50.0
height Determines width. Double 30.0
enabled Determines height. bool true
disabledOpacity Determines opacity of disabled control. double 0.5
thumb Custom thumb widget Widget

Demo

Flutter Advanced Switch Preview

Comments
  • Hover effect, courser to hand is missing

    Hover effect, courser to hand is missing

    Hi,

    Cool library! I use it for flutter web at the moment. But in web the users expect that the courser becoms a hand, if he hovers over the switch. Can you add this please?

    opened by Wissperwind 2
  • Update this library to Darts null safety

    Update this library to Darts null safety

    The next stable release of Flutter is using most probably Darts new null safety feature. Thus this library should be migrated.

    Please see the following links for further information: https://dart.dev/null-safety/migration-guide https://medium.com/flutter/announcing-dart-null-safety-beta-4491da22077a

    opened by ueman 2
  • Widget gets shown when not supposed to

    Widget gets shown when not supposed to

    https://user-images.githubusercontent.com/71348842/156032376-d1dbe2fb-3b26-4439-8f38-ce5aa521ec15.mp4

    image

    This issue from what I gather only happens when I run the app on ios

    opened by itamarsch 1
  • AnimationController.reverse() called after AnimationController.dispose()

    AnimationController.reverse() called after AnimationController.dispose()

    Hi Alex,

    I tried to add some switch items in my drawer. the first time on opening drawer everything is Ok. But when I close the drawer and re open it, I receive error:

    ======== Exception caught by foundation library ==================================================== The following assertion was thrown while dispatching notifications for AdvancedSwitchController: AnimationController.reverse() called after AnimationController.dispose() AnimationController methods should not be used after calling dispose. 'package:flutter/src/animation/animation_controller.dart': Failed assertion: line 488 pos 7: '_ticker != null'

    Thanks in Advance

    opened by Alijaaan 1
  • White Container Customizations

    White Container Customizations

    A very useful plugin for simple button implementation. However, currently, there is no way to customize the white container that moves right and left. In the Dark theme, that white container is too bright.

    image

    The White Container can be made customization which can accept a widget. If it accepts a Widget, we can use a custom moving block which may be a Custom Container or even an Icon.

    opened by TheCodeHealer 0
Releases(v3.0.1)
Owner
Alex Melnyk
A high skilled developer with 15 years of development experience. Working at https://litslink.com https://medium.alexmelnyk.io https://twitter.com/askMelnyk
Alex Melnyk
Flutter Color Picker Wheel - an easy to use widget which can be heavily customized

Flutter Color Picker Wheel Flutter Color Picker Wheel is an easy to use widget which can be heavily customized. You can use the WheelColorPicker direc

Kexin Lu 35 Oct 4, 2022
ListTileSwitch is simple widget that combines ListTile with a switch.

ListTileSwitch ListTileSwitch is a simple widget that combines ListTile with a switch. Offering 3 types of switch widgets: Switch: Material Switch fro

Fırat Çetiner 20 Nov 23, 2022
Progress Dialog widget for flutter projects with ability to customize loading widget, background color and background blur.

DISCONTINUED Checkout ArsDialog ars_progress_dialog Customizable progress dialog for Flutter applications with smooth animation for background dim col

Arsam 8 Apr 15, 2022
Flutter Package: When your desired layout or animation is too complex for Columns and Rows, this widget lets you position/size/rotate/transform its child in complex ways.

align_positioned Widgets in this package: AlignPositioned AnimatedAlignPositioned AnimChain Why are these widgets an indispensable tool? When your des

Marcelo Glasberg 69 Dec 12, 2022
Responsive Widgets Prefix allows you to add the "Responsive" prefix to any widget that needs scaling or font size increases

Responsive Widgets Prefix allows you to add the Responsive prefix to any widget that needs scaling or font size increases (for varying device screen sizes).

The Mobile Applications Community 2 Apr 18, 2022
Expanded Widget Advanced Design For Flutter

app_bar A new Flutter project. Getting Started This project is a starting point

HredayTheDev 0 Jan 16, 2022
AdvFAB - An Advanced floating action button that expands itself to reveal its hidden widget

AdvFAB (More Than Just A Floating Action Button) AdvFAB is An Advanced floating action button that expands itself to reveal its hidden widget. It can

null 19 Nov 4, 2022
A highly customizable toggle switch with a loading state.

A highly customizable toggle switch with a loading state.

null 6 Dec 30, 2022
A draggable Flutter widget that makes implementing a Sliding up and fully-stretchable much easier.

Draggable Home A draggable Flutter widget that makes implementing a Sliding up and fully-stretchable much easier! Based on the Scaffold and Sliver. Us

Devs On Flutter 106 Dec 12, 2022
Flutter reaction button plugin it is fully customizable widget such as Facebook reaction button

Flutter Reaction Button Flutter button reaction it is fully customizable widget such as Facebook reaction button. Preview Demo Usage Include 'flutter_

Abdelouahed Medjoudja 174 Dec 19, 2022
The color of the widget is different with the counter application

GoldenTestのお試しをしてみた https://pub.dev/packages/golden_toolkit このライブラリを使って、検証する ちなみにマスターのスクリーンショットをGoldenというらしい。 カウンターアプリでWidgetのカラーが違う場合をテストしてみた OK想定 NG

MatsumaruTsusyoshi 0 Oct 18, 2021
An advanced flutter package to build responsive application accross all platform with ease and has an handful of different types of extension

Flutter Next Now build flutter apps with ease and responsive. An advanced flutter package to build responsive application accross all platform with ea

Shashi Kumar 10 Dec 29, 2022
Flutter package: Define a theme (colors, text styles etc.) as static const values which can be changed dynamically.

Flutter package: Define a theme (colors, text styles etc.) as static const values which can be changed dynamically. Also comes with useful extensions to create text styles by composition.

Marcelo Glasberg 21 Jan 2, 2023
Widget, that can make any static located widget hidable

Installing See the official installing guidline from hidable/install Usage & Overview To start using Hidable widget, we have to create a ScrollControl

Anon 18 Dec 16, 2022
A widget lib that the widget in this lib can react to flutter ScrollController's offset

Language: English | 中文简体 linked_scroll_widgets A lib full of widgets that can react to the scrollController's offset change,to custom your UI effect.

WenJingRui 8 Oct 16, 2022
A Flutter Text widget support word break for CJK

word_break_text Text widget with word break support for CJK sentence. Installation Add flutter_map to your pubspec: dependencies: word_break_text:

ChangJoo Park(박창주) 5 Nov 11, 2022
Flutter widget to show text in popup or overlay container

flutter_show_more_text_popup Flutter widget to show text in popup or overlay container Installation Add this to your package's pubspec.yaml file depen

Sanjay Sharma 44 Jul 5, 2022
A Flutter widget to show a text form field to display a date or clock dialog

A Flutter widget to show a text form field to display a date or clock dialog. This widget extend TextField and has a similar behavior as TextFormField.

m3uzz Soluções em TI 82 Jan 6, 2023
A Flutter widget that scrolls text infinitely

⏩ A Flutter widget that scrolls text infinitely. Provides many customizations including custom scroll directions, durations, curves as well as pauses after every round.

Marcel Garus 219 Dec 29, 2022