Toggle Switch - A simple toggle switch widget. It can be fully customized with desired icons, width, colors, text, corner radius etc. It also maintains selection state.
Package selection guidance compiled from public package information, community data, and project usage.
A customizable toggle switch widget for Flutter that supports full customization of appearance and behavior. Users can adjust width, colors, icons, text, corner radius, and more. It maintains selection state across rebuilds and is suitable for various UI needs requiring on/off toggling. The package is lightweight and compatible with all major platforms including mobile, web, and desktop.
Use cases
User preference settings
On/off feature toggles
Form input controls
Dark mode switches
Profile configuration panels
Key features
Fully customizable design
Maintains selection state
Supports icons and text
Cross-platform compatibility
Adjustable size and styling
Simple API integration
Suitable for
Developers building responsive UIs
Apps needing toggle-based inputs
Customizable form components
Multi-platform Flutter projects
Considerations
Requires manual handling of state in some cases
Limited built-in animations
Best suited for simple toggle logic
Not ideal for complex interactive widgets
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
Toggle Switch
A simple toggle switch widget. It can be fully customized with desired icons, width, colors, text, corner radius, animation etc. It also maintains selection state.
Getting Started
In the pubspec.yaml of your flutter project, add the following dependency:
dependencies:...toggle_switch:^2.3.0
Import it:
import'package:toggle_switch/toggle_switch.dart';
Usage Examples
Basic toggle switch
// Here, default theme colors are used for activeBgColor, activeFgColor, inactiveBgColor and inactiveFgColorToggleSwitch(
initialLabelIndex: 0,
totalSwitches: 3,
labels: ['America', 'Canada', 'Mexico'],
onToggle: (index) {
print('switched to: $index');
},
),
Basic toggle switch with custom height and font size
// When ToggleSwitch is used with Directionality widget and textDirection is set to TextDirection.rtl (right-to-left), // switches are displayed right to left along with their respective index values. In this case, corner radius of switches aren't set correctly. // To fix this, please use textDirectionRTL parameter and set it to true as shown in the example below. Directionality(
textDirection: TextDirection.rtl,
child: ToggleSwitch(
initialLabelIndex: 0,
cornerRadius: 12.0,
textDirectionRTL: true,
activeFgColor: Colors.white,
totalSwitches: 2,
labels: ['left', 'right'],
onToggle: (index) {
print('switched to: $index');
},
),
),