load_switch 1.2.0 copy "load_switch: ^1.2.0" to clipboard
load_switch: ^1.2.0 copied to clipboard

A highly customizable toggle switch with a loading state. Useful when getting data from remote calls.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:load_switch/load_switch.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool value = false;

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Load Switch Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          LoadSwitch(
            value: value,
            future: _getFuture,
            onChange: (v) {
              value = v;
              print('Value changed to $v');
              setState(() {});
            },
            onTap: (v) {
              print('Tapping while value is $v');
            },
          ),
        ],
      ),
    );
  }
}
42
likes
160
pub points
90%
popularity

Publisher

verified publisheresentis.dev

A highly customizable toggle switch with a loading state. Useful when getting data from remote calls.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on load_switch