Skip to content

Instantly share code, notes, and snippets.

@chchchchch123c
Last active June 19, 2025 15:22
Show Gist options
  • Save chchchchch123c/9d33f1d2237201117e27cce2c974c895 to your computer and use it in GitHub Desktop.
Save chchchchch123c/9d33f1d2237201117e27cce2c974c895 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: Test()));
class Test extends StatefulWidget {
const Test({super.key});
@override
State<Test> createState() => _TestState();
}
class _TestState extends State<Test> {
List<bool> isSelected = [true, false, false];
void onPressed(int index) {
setState(() {
for (int i = 0; i < isSelected.length; i++) {
isSelected[i] = i == index;
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ToggleButtons(
onPressed: (index) => onPressed(index),
isSelected: isSelected,
children: [
Icon(Icons.local_cafe),
Icon(Icons.fastfood),
Icon(Icons.cake),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment