Skip to content

Instantly share code, notes, and snippets.

@shihaohong
Last active June 26, 2019 17:13
Show Gist options
  • Save shihaohong/f559c8dc06beb684ce01e76b07dc01c9 to your computer and use it in GitHub Desktop.
Save shihaohong/f559c8dc06beb684ce01e76b07dc01c9 to your computer and use it in GitHub Desktop.
From local flutter/flutter repo, `git checkout -b shihaohong-toggle-button master`, then `git pull https://github.com/shihaohong/flutter.git toggle-button`
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ToggleButtons Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: ToggleButtonPlayground(title: 'ToggleButtons Demo Page'),
);
}
}
class ToggleButtonPlayground extends StatefulWidget {
ToggleButtonPlayground({Key key, this.title}) : super(key: key);
final String title;
@override
_ToggleButtonPlaygroundState createState() => _ToggleButtonPlaygroundState();
}
class _ToggleButtonPlaygroundState extends State<ToggleButtonPlayground> {
List<bool> isSelected = [
true,
false,
true,
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ToggleButtonsTheme(
child: Center(
child: ToggleButtons(
children: <Widget>[
Icon(Icons.ac_unit),
Icon(Icons.call),
Icon(Icons.cake),
],
onPressed: (int index) {
setState(() {
isSelected[index] = !isSelected[index];
});
},
isSelected: isSelected,
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment