Coder Social home page Coder Social logo

esentis / load_switch Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 2.0 755 KB

A highly customizable toggle switch with a loading state.

Home Page: https://pub.dev/packages/load_switch

License: BSD 3-Clause "New" or "Revised" License

Kotlin 0.43% Swift 1.39% Objective-C 0.13% Dart 84.53% HTML 13.52%
flutter flutter-widget switch toggle-switch loading-switch

load_switch's Introduction

Version Version
Publish to Pub.dev

Examples

bool value = false;

Future<bool> _getFuture() async {
    await Future.delayed(const Duration(seconds: 2));
    return !value;
}

Default

Version

LoadSwitch(
    value: value,
    future: _getFuture,
    style: SpinStyle.material
    onChange: (v) {
        value = v;
        print('Value changed to $v');
        setState(() {});
    },
    onTap: (v) {
        print('Tapping while value is $v');
    },
)

Custom

Version

LoadSwitch(
value: value,
future: _getFuture,
style: SpinStyle.material
curveIn: Curves.easeInBack,
curveOut: Curves.easeOutBack,
animationDuration: const Duration(milliseconds: 500),
switchDecoration: (value) => BoxDecoration(
    color: value ? Colors.green[100] : Colors.red[100],
    borderRadius: BorderRadius.circular(30),
    shape: BoxShape.rectangle,
    boxShadow: [
    BoxShadow(
        color: value
            ? Colors.green.withOpacity(0.2)
            : Colors.red.withOpacity(0.2),
        spreadRadius: 5,
        blurRadius: 7,
        offset: const Offset(0, 3), // changes position of shadow
    ),
    ],
),
spinColor: (value) => value
    ? const Color.fromARGB(255, 41, 232, 31)
    : const Color.fromARGB(255, 255, 77, 77),
spinStrokeWidth: 3,
thumbDecoration: (value) => BoxDecoration(
    color: Colors.white,
    borderRadius: BorderRadius.circular(30),
    shape: BoxShape.rectangle,
    boxShadow: [
    BoxShadow(
        color: value
            ? Colors.green.withOpacity(0.2)
            : Colors.red.withOpacity(0.2),
        spreadRadius: 5,
        blurRadius: 7,
        offset: const Offset(0, 3), // changes position of shadow
    ),
    ],
),
onChange: (v) {
    value = v;
    print('Value changed to $v');
    setState(() {});
},
onTap: (v) {
    print('Tapping while value is $v');
},
),

Spin styles

The library extends flutter_spinkit internally adding some fancy spin animations. Keep in mind you can also edit the thumbDecoration & switchDecoration for different color & shapes. The examples have the default circular thumb with white color. The default style is SpinStyle.material.

material cupertino chasingDots
material cupertino chasingDots
circle cubeGrid dancingSquare
circle cubeGrid dancingSquare
doubleBounce dualRing fadingCircle
doubleBounce dualRing fadingCircle
fadingCube fadingFour fadingGrid
fadingCube fadingFour fadingGrid
foldingCube hourGlass pianoWave
foldingCube hourGlass pianoWave
pouringHourGlass pulse pulsingGrid
pouringHourGlass pulse pulsingGrid
pumpingHeart ring ripple
pumpingHeart ring ripple
rotatingCircle rotatingPlain spinningCircle
rotatingCircle rotatingPlain spinningCircle
spinningLines squareCircle threeBounce
spinningLines squareCircle threeBounce
threeInOut wanderingCubes waveStart
threeInOut wanderingCubes waveStart
waveCenter waveEnd waveSpinner
waveCenter waveEnd waveSpinner

Issues / Features

Found a bug or want a new feature? Open an issue in the Github repository of the project.

load_switch's People

Contributors

esentis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.