Skip to content

Instantly share code, notes, and snippets.

@NebulaFox
Last active October 4, 2020 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NebulaFox/d632c78dc60556c24e7700791a327fcf to your computer and use it in GitHub Desktop.
Save NebulaFox/d632c78dc60556c24e7700791a327fcf to your computer and use it in GitHub Desktop.
Showing ToggleButtons does not remove border
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Toggle Button',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Toggle Button'),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: ChooseIcon(),
),
);
}
}
class ChooseIcon extends StatefulWidget {
@override
ChooseIconState createState() => ChooseIconState();
}
class ChooseIconState extends State<ChooseIcon> {
final icons = [
Icon(Icons.ac_unit),
Icon(Icons.call),
Icon(Icons.cake),
];
List<bool> _selection;
@override
void initState() {
super.initState();
_selection = List.filled(icons.length, false);
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Spacer(),
ToggleButtons(
borderWidth: null, // should remove border
children: icons,
isSelected: _selection,
onPressed: (int index) {
setState(() {
for (int buttonIndex = 0; buttonIndex < _selection.length; buttonIndex++) {
if (buttonIndex == index) {
_selection[buttonIndex] = !_selection[buttonIndex];
} else {
_selection[buttonIndex] = false;
}
}
});
},
),
Spacer(),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment