toggle_switch 0.0.1 toggle_switch: ^0.0.1 copied to clipboard
A simple toggle switch widget.
import 'package:flutter/material.dart';
import 'package:toggle_switch/toggle_switch.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ToggleSwitch(
minWidth: 90.0,
initialLabel: 2,
activeBgColor: Colors.redAccent,
activeTextColor: Colors.white,
inactiveBgColor: Colors.grey,
inactiveTextColor: Colors.grey[900],
labels: ['America', 'Canada', 'Mexico'],
onToggle: (index) {
print('switched to: $index');
},
),
SizedBox(height: 16),
ToggleSwitch(
cornerRadius: 20,
activeBgColor: Colors.green,
activeTextColor: Colors.white,
inactiveBgColor: Colors.grey,
inactiveTextColor: Colors.white,
labels: ['YES', 'NO'],
),
],
),
),
),
);
}
}