power_switch_button 0.0.3 copy "power_switch_button: ^0.0.3" to clipboard
power_switch_button: ^0.0.3 copied to clipboard

PowerSwitchButton is a customizable Flutter switch widget with adjustable size, stroke width, dash width, and dash space for a stylish toggle switch.

PowerSwitchButton #

PowerSwitchButton is a versatile and customizable switch widget for Flutter that allows you to easily add a stylish toggle switch to your applications. With adjustable parameters for size, stroke width, dash width, and dash space, this widget provides a modern, eye-catching switch with customizable on and off colors.

Features #

  • Customizable Size: Adjust the size of the switch to fit your design needs.
  • Adjustable Stroke and Dash: Control the stroke width, dash width, and dash space to match your app's aesthetic.
  • Color Options: Set different colors for the switch in its on and off states.
  • Callback Function: Receive a callback with the switch state whenever it is toggled.

Demo #

Screen_recording_20240801_143600-ezgif com-resize

Installation #

Add the following to your pubspec.yaml file:

dependencies:
  power_switch_button: ^0.0.3

Usage #

Import the Package

import 'package:power_switch_button/power_switch_button.dart';

Basic Example #

Here is a basic example of how to use the CustomSwitch widget in your application:

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.white,
        body: Center(
          child: PowerSwitchButton(
            size: 200,
            strokeWidth: 4,
            dashWidth: 1,
            dashSpace: 2,
            onColor: Colors.red,
            offColor: Colors.grey,
            backgroundColor: Colors.black,
            iconColor: Colors.black,
            onToggle: (bool isOn) {
              print('Switch is ${isOn ? 'On' : 'Off'}');
            },
          ),
        ),
      ),
    );
  }
}

Parameters #

  • size: The size of the switch (e.g., 200).
  • strokeWidth: The width of the dashed stroke (e.g., 4).
  • dashWidth: The width of each dash in the dashed circle (e.g., 1).
  • dashSpace: The space between each dash in the dashed circle (e.g., 2).
  • onColor: The color of the switch when it is in the 'on' position (e.g., Colors.red).
  • offColor: The color of the switch when it is in the 'off' position (e.g., Colors.grey).
  • backgroundColor: The color of the switch background (e.g., Colors.black).
  • iconColor: The color of the icon (e.g., Colors.black).
  • onToggle: A callback function that receives the switch's state (true for on, false for off).

License #

This package is licensed under the MIT License. See the LICENSE file for more details.

9
likes
0
points
10
downloads

Publisher

unverified uploader

Weekly Downloads

PowerSwitchButton is a customizable Flutter switch widget with adjustable size, stroke width, dash width, and dash space for a stylish toggle switch.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

cupertino_icons, flutter

More

Packages that depend on power_switch_button