I need selectable buttoon in flutter - flutter

what i get_____whai i wantbut when i use ToggleButttons i cant change its shape(i need rounded), and cant put more distance beetwen buttons. Toggle button is list in which put icons. But how i can make selectabe(only one of thr buuton) without toggle like in exaple or with toglleButoon
class MyToggleButtonsState extends State<MyToggleButtons> {
List<bool> iSselected = List.generate(4,(index)=> false);
List<IconData> icon = [MyFlutterApp.mobile,Icons.computer,Icons.monitor_heart,Icons.collections_bookmark_sharp ];
#override
Widget build(BuildContext context) {
return ToggleButtons(
selectedColor: Colors.white,
renderBorder: false,
isSelected: iSselected,
fillColor: Colors.orange,
onPressed: (int newIndex) {
setState(() {
for(int index = 0; index < iSselected.length; index++){
if(index == newIndex){
iSselected[index] = true;
} else{
iSselected[index] = false;
}
}
});
},
children: [
CustomIcon(
radius: BorderRadius.circular(32.0),
isSelected: iSselected[0],
icon: const Icon(MyFlutterApp.mobile),
),
CustomIcon(
radius: BorderRadius.circular(32.0),
isSelected: iSselected[1],
icon: const Icon(Icons.computer)
),
CustomIcon(
radius: BorderRadius.circular(32.0),
isSelected: iSselected[2],
icon: const Icon(Icons.monitor_heart)
),
CustomIcon(
radius: BorderRadius.circular(32.0),
isSelected: iSselected[3],
icon: const Icon(Icons.collections_bookmark_sharp)
)
]
);[What i want][1][What i can][1]
}
}
Thank you very much

You can achieve this by doing the following!
class CustomPageWithToggle extends StatefulWidget {
const CustomPageWithToggle({Key? key}) : super(key: key);
#override
State<CustomPageWithToggle> createState() => _CustomPageWithToggleState();
}
class _CustomPageWithToggleState extends State<CustomPageWithToggle> {
List<bool> isSelected = List.generate(5, (index) => false);
List<IconData> icons = [Icons.phone_android, Icons.computer, Icons.monitor_heart, Icons.menu_book, Icons.fastfood];
List<String> texts = ['Phones', 'Computers', 'Health', 'Books', 'Food'];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Example'),
),
backgroundColor: const Color.fromARGB(255, 218, 218, 218),
body: Column(
children: [
const SizedBox(
height: 10,
),
CustomToggle(
icons: icons,
texts: texts,
setStateFunction: setState,
isSelected: isSelected,
),
// Put Your Content Here
],
),
);
}
}
class CustomToggle extends StatelessWidget {
final List<IconData> icons;
final List<String> texts;
final Function setStateFunction;
final List<bool> isSelected;
const CustomToggle({
Key? key,
required this.icons,
required this.texts,
required this.setStateFunction,
required this.isSelected,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
// You should use this widget: SingleChildScrollView if your ToggleButtons are too long and overflow the screen.
// This makes it scrollable. If yours will not overflow, you can remove this widget.
scrollDirection: Axis.horizontal,
child: ToggleButtons(
isSelected: isSelected,
onPressed: (index) {
setStateFunction(() {
for (int i = 0; i < isSelected.length; i++) {
if (i == index) {
isSelected[i] = true;
} else {
isSelected[i] = false;
}
}
});
},
renderBorder: false,
fillColor: Colors.transparent,
splashColor: Colors.orange,
// Include other design properties if needed.
children: List<Widget>.generate(icons.length, (index) {
return CustomButton(
text: texts[index],
icondata: icons[index],
isSelected: isSelected[index],
);
}),
),
);
}
}
class CustomButton extends StatelessWidget {
final String text;
final IconData icondata;
final bool isSelected;
const CustomButton({
Key? key,
required this.text,
required this.icondata,
this.isSelected = false,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Column(
children: [
Container(
width: 70,
height: 70,
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
color: isSelected ? Colors.orange : Colors.white,
shape: BoxShape.circle,
),
child: Icon(
icondata,
color: isSelected ? Colors.white : Colors.grey,
),
),
const SizedBox(height: 10),
Text(
text,
style: TextStyle(
color: isSelected ? Colors.orange : Colors.grey,
),
),
],
);
}
}
Explanation:
Using the ToggleButtons widget is the right choice for this. But as you said, using the properties of ToggleButtons can't create the button design you want. Therefore you have to provide your own custom button to the ToggleButtons child propaties.
Also, one important change I made to your code is, your code has the state controlled in the MyToggleButtons. But, mine is controlled at the Parent Widget(CustomPageWithToggle) not the CustomToggle. Yours will also work for your Toggle button but, the widget outside(parent widget, etc) can't access the isSelected list (Which probably you may want to use outside the toggle button). Notice with my code that any widget inside CustomPageWithToggle can access the isSelected variable.
Result:
If you don't understand or have questions leave a comment and I'll answer!

Related

why is (_selected) in Widged _button undfined

in the Widget _button it says:
Undefined name '_selected'.
Try correcting the name to one that is defined, or defining the name.dartundefined_identifier
But I defined at in Widget section please help
or say me what do i wrong
it is the same with _setState
class NavBar extends StatefulWidget {
const NavBar({Key? key}) : super(key: key);
#override
_NavBarState createState() => _NavBarState();
}
class _NavBarState extends State<NavBar> {
final _palette = AppTheme.palette;
int _selected = 0;
#override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: _palette.primaryColor,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_button(
index: 0,
icon: Icons.home,
selectedIndex: _selected,
),
_button(
index: 1,
icon: Icons.favorite_border_outlined,
selectedIndex: _selected,
),
],
),
);
}
}
on the same page is the Widget _button
Widget _button({
required int index,
required IconData icon,
VoidCallback? onPressed,
int selectedIndex: 0,
}) {
bool isSelected = selectedIndex == index;
return Material(
color: isSelected ? AppTheme.palette.buttonOverlay : Colors.transparent,
borderRadius: BorderRadius.circular(13),
clipBehavior: Clip.antiAlias,
child: IconButton(
visualDensity: VisualDensity.compact,
icon: Icon(
icon,
color: isSelected
? AppTheme.palette.secondaryColor
: AppTheme.palette.buttonOverlay,
),
onPressed: () {
_selected = index;
onPressed?.call();
setState(() {});
},
),
);
}
...on the same page is the Widget _button
You need to make sure that _button is within your NavBar class. It should look like this:
class NavBar extends StatefulWidget {
const NavBar({Key? key}) : super(key: key);
#override
_NavBarState createState() => _NavBarState();
}
class _NavBarState extends State<NavBar> {
final _palette = AppTheme.palette;
int _selected = 0;
#override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: _palette.primaryColor,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_button(
index: 0,
icon: Icons.home,
selectedIndex: _selected,
),
_button(
index: 1,
icon: Icons.favorite_border_outlined,
selectedIndex: _selected,
),
],
),
);
}
Widget _button({
required int index,
required IconData icon,
VoidCallback? onPressed,
int selectedIndex: 0,
}) {
bool isSelected = selectedIndex == index;
return Material(
color: isSelected ? AppTheme.palette.buttonOverlay : Colors.transparent,
borderRadius: BorderRadius.circular(13),
clipBehavior: Clip.antiAlias,
child: IconButton(
visualDensity: VisualDensity.compact,
icon: Icon(
icon,
color: isSelected
? AppTheme.palette.secondaryColor
: AppTheme.palette.buttonOverlay,
),
onPressed: () {
_selected = index;
onPressed?.call();
setState(() {});
},
),
);
}
}
Make sure your _button method is inside the _NavBarState class, otherwise you can't access the global data inside it.

Didn't change the color of container

I want to change the color of the Container when it is pressed and go to the new screen but when I come back the color must have changed.
class FreelancerLayout extends StatefulWidget {
const FreelancerLayout({Key? key}) : super(key: key);
#override
State<FreelancerLayout> createState() => _FreelancerLayoutState();
}
class _FreelancerLayoutState extends State<FreelancerLayout>
with AutomaticKeepAliveClientMixin<FreelancerLayout> {
#override
Widget build(BuildContext context) {
super.build(context);
return SingleChildScrollView(
physics: const BouncingScrollPhysics(),
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0),
child: GridView.builder(
itemCount: catList.length,
shrinkWrap: true,
primary: false,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 8.0,
mainAxisSpacing: 10.0),
itemBuilder: (context, index) => Center(
child: GridCategory(
category: catList[index],
press: () {
pushNewScreen(context,
screen: CategoryPage(category: catList[index]));
}),
),
),
),
GridCategory.dart
class GridCategory extends StatefulWidget {
final Category category;
final VoidCallback? press;
const GridCategory({
Key? key,
required this.category,
this.press,
// required this.selectedIcon,
// required this.unSelectedIcon,
}) : super(key: key);
#override
State<GridCategory> createState() => _GridCategoryState();
}
class _GridCategoryState extends State<GridCategory> {
final bool isSelected = false;
#override
Widget build(BuildContext context) {
return InkWell(
onTap: widget.press,
child: Container(
width: 110,
decoration: BoxDecoration(
color: isSelected ? AppColors.fIconsAndTextColor : Colors.white,
borderRadius: BorderRadius.circular(30.0)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(child: Image.asset(widget.category.catImage!)),
Text(
widget.category.iconName!,
textAlign: TextAlign.center,
style: TextStyle(color: isSelected ? Colors.white : Colors.black),
),
const SizedBox(height: 10)
],
),
),
);
}
}
First, I don't see any method to change isSelected here, soo it value alway false. Second, isSelected is final make it value can't changes, remove final. Thirt, because isSelected is local props, it changes will no appear in other page, you need to passing selected from parent if you want it.
Update: In case you want highlight selected category when selected and change it when select other cate? You need create a variable call 'selectedIndex' to store the selected category index, handle changes it everytime u tap a category. Update code below
_FreelancerLayoutState
...
int? selectedIndex; // Add this
#override
Widget build(BuildContext context) {
...
itemBuilder: (context, index) => Center(
child: GestureDetector(
onPressed: () {
setState(() => selectedIndex = index);
pushNewScreen(
context,
screen: CategoryPage(category: catList[index])
);
},
child: GridCategory(
category: catList[index],
isSelected: selectedIndex == index,
),
),
),
...
}
}
GridCategory
class GridCategory extends StatefulWidget {
...
final Category category;
final bool isSelected; // add this
// final VoidCallback? press; Remove this
...
}
_GridCategoryState
...
// final bool isSelected = false; Remove this
...
#override
Widget build(BuildContext context) {
// Removed InkWell
// return InkWell(
// onTap: widget.press,
// child: ...
// );
return Container(
width: 110,
decoration: BoxDecoration(
color: widget.isSelected ? AppColors.fIconsAndTextColor : Colors.white,
borderRadius: BorderRadius.circular(30.0)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(child: Image.asset(widget.category.catImage!)),
Text(
widget.category.iconName!,
textAlign: TextAlign.center,
style: TextStyle(color: widget.isSelected ? Colors.white : Colors.black),
),
const SizedBox(height: 10)
],
),
),
}
...
Change the GridCategory widget to a stateful widget. Then you can update the onTap function to change the boolean and then call the callback.
onTap: (){
setState((){
isSelected = true;
});
press();
},
On your GridCategory widget, pass isSelected from parent.
class GridCategory extends StatelessWidget {
final Category category;
final VoidCallback? press;
final bool isSelected;
const GridCategory({
Key? key,
required this.isSelected,
required this.category,
this.press,
}) : super(key: key);
......
To keep track of selected index you need a list, I am using List<int> here,
class _FreelancerLayoutState extends State<FreelancerLayout>
with AutomaticKeepAliveClientMixin<FreelancerLayout> {
List<int> selectedIndex = [];
....
itemBuilder: (context, index) => Center(
child: GridCategory(
isSelected: selectedIndex.contains(index),
press: () {
if (selectedIndex.contains(index)) {
selectedIndex.remove(
index); // remove selected index if already exist
} else {
selectedIndex.add(index);
}
//... perform others
}),

Function callback to change text color (just for one) | Flutter

I'm trying to create a SideMenu with different SideMenuItems.
For that I created a new class and want to update the color of Text when the SideMenuItem is clicked. For that I want to transfer the activeState and all that stuff you see in the code below:
The use of my class in the Widget:
bool isActive = false;
...
SideMenuItem(
icon: Icon(
Icons.inbox,
size: 20,
color: isActive ? kPrimaryColor : kGrayColor,
),
activeState: isActive,
title: "Archiv",
toggleActiveState: (activeState) {
setState(() {
isActive = !activeState;
});
},
),
And here is my class:
import 'package:flutter/material.dart';
import 'package:gastronomy/constants.dart';
class SideMenuItem extends StatelessWidget {
// ignore: prefer_const_constructors_in_immutables
SideMenuItem({
Key? key,
required this.activeState,
this.itemCount = 0,
this.showBorder = true,
#required this.icon,
#required this.title,
required this.toggleActiveState,
}) : super(key: key);
final bool activeState;
final bool showBorder;
final int itemCount;
final Icon? icon;
final String? title;
final Function(bool) toggleActiveState;
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: kDefaultPadding),
child: InkWell(
onTap: () {
toggleActiveState(activeState);
},
child: Row(
children: [
const SizedBox(width: 15),
const SizedBox(width: kDefaultPadding / 4),
Expanded(
child: Container(
padding: const EdgeInsets.only(bottom: 15, right: 5),
decoration: showBorder
? const BoxDecoration(
border: Border(
bottom: BorderSide(color: Color(0xFFDFE2EF)),
),
)
: null,
child: Row(
children: [
icon!,
const SizedBox(width: kDefaultPadding * 0.75),
Text(
title!,
style: Theme.of(context).textTheme.button?.copyWith(
color: activeState ? kTextColor : kGrayColor,
),
),
const Spacer(),
// if (itemCount != null) CounterBadge(count: itemCount)
],
),
),
),
],
),
),
);
}
}
I ended up with that pieces of code but well, how you might know, all SideMenuItems change there color when I click one.
I'm pretty new at using this way of code so I would be thankful to all informations you can include into your answer.
One option is to render all the menu items through a map function and compare each item with the selected option, like in the example below:
import 'package:flutter/material.dart';
class MenuExample extends StatefulWidget {
const MenuExample({Key? key}) : super(key: key);
#override
_MenuExampleState createState() => _MenuExampleState();
}
class _MenuExampleState extends State<MenuExample> {
List<String> menuOptions = const ['Item 1', 'Item 2', 'Item 3'];
String selectedOption = '';
#override
Widget build(BuildContext context) {
return Scaffold(
drawer: Drawer(
backgroundColor: Colors.amber,
child: ListView(
children: menuOptions.map((menuOption) {
return InkWell(
onTap: () => setState(() {
selectedOption = menuOption;
}),
child: MenuItem(
name: menuOption,
isSelected: menuOption == selectedOption,
),
);
}).toList()),
),
);
}
}
class MenuItem extends StatelessWidget {
const MenuItem({Key? key, this.isSelected = false, required this.name})
: super(key: key);
final bool isSelected;
final String name;
#override
Widget build(BuildContext context) {
return ListTile(
title: Text(
name,
style: TextStyle(
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal),
),
);
}
}

Flutter: Changing color on button press of class in List

I've seen variations of this question but haven't been able to quite piece together a solution for my use case.
I have a list of CircleButton.
List<CircleButton> buttons = [
new CircleButton(onTap: () => print("Arts"), iconData: Icons.palette, label: "Arts"),
new CircleButton(onTap: () => print("Board Games"), iconData: Icons.casino, label: "Board Games"),
new CircleButton(onTap: () => print("Causes"), iconData: Icons.volunteer_activism, label: "Causes"),
];
I display these in a GridView
Widget interests() {
return Expanded(
child:
SizedBox(
height: 200.0,
child:
GridView.count(
primary: false,
padding: const EdgeInsets.all(20),
crossAxisSpacing: 10,
mainAxisSpacing: 10,
crossAxisCount: 4,
children: <Widget>[
for (var button in buttons) Column( children: [ button, Text(button.label)],)
],
)
)
);
}
When the button is tapped I want to update how it looks. I have set up the CircleButton class to have the boolean value isSelected to determine how the coloring should be:
class CircleButton extends StatelessWidget {
final GestureTapCallback onTap;
final IconData iconData;
final String label;
bool isSelected = false;
CircleButton({Key key, this.onTap, this.iconData, this.label}) : super(key: key);
#override
Widget build(BuildContext context) {
double size = 65.0;
return new
InkResponse(
onTap: onTap,
child: new Container(
width: size,
height: size,
decoration: new BoxDecoration(
color: isSelected ? Color.fromRGBO(139, 207, 236, 1.0) : Color.fromRGBO(248, 248, 250, 1.0),
shape: BoxShape.circle,
),
child: new Icon(
iconData,
color: isSelected ? Colors.white : Color.fromRGBO(2, 78, 157, 1.0),
),
),
);
}
}
How can I update the isSelected variable from onTap?
If you want each button to manage its own selected state (meaning that tapping on a button will not unselect the others), you must use StatefulWidget :
class CircleButton extends StatefulWidget {
final GestureTapCallback onTap;
final IconData iconData;
final String label;
CircleButton({Key key, this.onTap, this.iconData, this.label})
: super(key: key);
#override
_CircleButtonState createState() => _CircleButtonState();
}
class _CircleButtonState extends State<CircleButton> {
bool isSelected = false;
#override
Widget build(BuildContext context) {
double size = 65.0;
return new InkResponse(
onTap: () {
widget.onTap;
// ADD THESE LINES
setState(() {
isSelected = !isSelected;
});
},
child: new Container(
width: size,
height: size,
decoration: new BoxDecoration(
color: isSelected
? Color.fromRGBO(139, 207, 236, 1.0)
: Color.fromRGBO(248, 248, 250, 1.0),
shape: BoxShape.circle,
),
child: new Icon(
widget.iconData,
color: isSelected ? Colors.white : Color.fromRGBO(2, 78, 157, 1.0),
),
),
);
}
}
Otherwise, if you want only one button to be selected at a time, juste create a variable in the parent widget that stores which button is selected :
int selectedButtonIndex;
List<CircleButton> buttons = [
new CircleButton(onTap: () {
print("Arts");
setState((){ selectedButtonIndex = selectedButtonIndex != 0 ? 0 : null; });
}, iconData: Icons.palette, label: "Arts",
isSelected: selectedButtonIndex == 0,
),
new CircleButton(onTap: () {
print("Board Games");
setState((){ selectedButtonIndex = selectedButtonIndex != 1 ? 1 : null; });
}, iconData: casino, label: "Board Games",
isSelected: selectedButtonIndex == 1,
),
...
];
And add isSelected as a parameter for CircleButton

ToggleButtons, Flutter: How to change border color and border radius

I have 3 ToggleButtons and I'm trying to figure out how to change the color of the selected button's border. As you can see in my picture, the green button on the left has a very hard to see light blue border around it since it is the selected button. I would like to know how I can change this color and also how I can round the border's corners.
If it helps, 'CryptoCard' is made with the Card class.
Here is my code:
Center(
child: ToggleButtons(
borderWidth: 0,
splashColor: Colors.yellow,
renderBorder: false,
children: <Widget>[
CryptoCard(
selectedCurrency,
snapshot.connectionState ==
ConnectionState.waiting
? '---'
: coinData[0],
'Bitcoin'),
CryptoCard(
selectedCurrency,
snapshot.connectionState ==
ConnectionState.waiting
? '---'
: coinData[1],
'Ethereum'),
CryptoCard(
selectedCurrency,
snapshot.connectionState ==
ConnectionState.waiting
? '---'
: coinData[2],
'Litecoin'),
],
onPressed: (int index) {
setState(() {
for (int buttonIndex = 0;
buttonIndex < isSelectedCrypto.length;
buttonIndex++) {
if (buttonIndex == index) {
isSelectedCrypto[buttonIndex] = true;
selectedCrypto =
cryptoAbbreviation[buttonIndex];
print("selectedCrypto");
print(selectedCrypto);
} else {
isSelectedCrypto[buttonIndex] = false;
}
}
});
futureData = getData();
},
isSelected: isSelectedCrypto))
ToggleButton has a property selectedBorderColor which you can use to set the border color of your selected button. You can use a custom widget to give rounded border to each individual button.
Please see the code below :
import 'package:flutter/material.dart';
final Color darkBlue = const Color.fromARGB(255, 18, 32, 47);
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<bool> isSelected = List.generate(6, (index) => false);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: ToggleButtons(
children: [
CustomIcon(
icon: const Icon(Icons.ac_unit),
isSelected: isSelected[0],
bgColor: const Color(0xfff44336),
),
CustomIcon(
icon: const Icon(Icons.call),
isSelected: isSelected[1],
bgColor: const Color(0xffE91E63),
),
CustomIcon(
icon: const Icon(Icons.cake),
isSelected: isSelected[2],
bgColor: const Color(0xff9C27B0),
),
CustomIcon(
icon: const Icon(Icons.add),
isSelected: isSelected[3],
bgColor: const Color(0xff673AB7),
),
CustomIcon(
icon: const Icon(Icons.accessibility),
isSelected: isSelected[4],
bgColor: const Color(0xff3F51B5),
),
CustomIcon(
icon: const Icon(Icons.analytics),
isSelected: isSelected[5],
bgColor: const Color(0xff2196F3),
),
],
onPressed: (int index) {
setState(() {
for (int buttonIndex = 0;
buttonIndex < isSelected.length;
buttonIndex++) {
if (buttonIndex == index) {
isSelected[buttonIndex] = !isSelected[buttonIndex];
} else {
isSelected[buttonIndex] = false;
}
}
});
},
isSelected: isSelected,
selectedColor: Colors.amber,
renderBorder: false,
fillColor: Colors.transparent,
),
),
);
}
}
class CustomIcon extends StatefulWidget {
final Icon icon;
final bool isSelected;
final Color bgColor;
const CustomIcon(
{Key key,
this.icon,
this.isSelected = false,
this.bgColor = Colors.green})
: super(key: key);
#override
_CustomIconState createState() => _CustomIconState();
}
class _CustomIconState extends State<CustomIcon> {
#override
Widget build(BuildContext context) {
return Container(
width: 47,
height: 47,
decoration: BoxDecoration(
border: widget.isSelected
? Border.all(
color: const Color(0xffC5CAE9),
)
: null,
borderRadius: const BorderRadius.all(
Radius.circular(10),
),
),
child: Center(
child: Container(
height: 32,
width: 32,
decoration: BoxDecoration(
color: widget.bgColor,
borderRadius: const BorderRadius.all(
Radius.circular(5),
),
),
child: widget.icon,
),
),
);
}
}
I'm sure it is not the best but here is my code for this maybe it will help someone out there.
if you need only need one selected button to be colorized in different colour like this
Color mColor = Color(0xFF6200EE),mColor0 = Color(0xFF6200EE),mColor1 = Color(0xFF6200EE);
final isSelected = <bool>[false, false, false];
then
ToggleButtons(
color: Colors.black.withOpacity(0.60),
selectedColor: mColor,
selectedBorderColor: mColor0,
fillColor: mColor1.withOpacity(0.08),
splashColor: Colors.grey.withOpacity(0.12),
hoverColor: Color(0xFF6200EE).withOpacity(0.04),
borderRadius: BorderRadius.circular(4.0),
constraints: BoxConstraints(minHeight: 36.0),
isSelected: isSelected,
onPressed: (index) {
// Respond to button selection
setState(() {
isSelected[0] = false;
isSelected[1] = false;
isSelected[2] = false;
if (index == 0) {
mColor = Colors.blue;
mColor0 = Colors.blue;
mColor1 = Colors.blue;
}
if (index == 1) {
mColor = Colors.green;
mColor0 = Colors.green;
mColor1 = Colors.green;
}
if (index == 2) {
mColor = Colors.red;
mColor0 = Colors.red;
mColor1 = Colors.red;
}
isSelected[index] = !isSelected[index];
});
},
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: Text(
'BUTTON 1',
style: TextStyle(fontSize: 20),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: Text(
'BUTTON 2',
style: TextStyle(fontSize: 20),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: Text(
'BUTTON 3',
style: TextStyle(fontSize: 20),
),
),
],
),