I’m trying the new SegmentedButton
widget:
SegmentedButton<int>(
onSelectionChanged: (i) {},
showSelectedIcon: false,
style: ButtonStyle(
backgroundColor: MaterialStatePropertyAll(Theme.of(context).primaryColor),
iconColor: MaterialStateProperty.all(Colors.white),
),
segments: const <ButtonSegment<int>>[
ButtonSegment<int>(
value: 12,
icon: Icon(FlutterRemix.thumb_up_fill),
enabled: true,
),
ButtonSegment<int>(
value: 20,
icon: Icon(FlutterRemix.thumb_down_fill),
),
],
selected: {12},
),
This code shows the two segmented buttons like this:
How can I customize the color od the selected and unselected buttons, when I set:
backgroundColor: MaterialStatePropertyAll(Theme.of(context).primaryColor),
It does set the background color for both selected and selected.
Thank you!
2
Answers
According to my test, it only works if I remove
backgroundColor
and add other code:You can control this with Material States: