how to Display Json Data in dropdownlist in flutter - flutter

I have a JSON file with data that I want to display in my dropdownlist. How do I go about implementing this? I would appreciate any input. I currently have this hardcoded into my page unndes state and working but want to call it from json file. I've tried some answers on here with no luck. This is one of the errors that I got: type 'List<dynamic>' is not a subtype of type 'List<String>' Changing the code and moving stuff around only gave more errors.
class SearchFilters extends StatefulWidget {
#override
_SearchFiltersState createState() => _SearchFiltersState();
}
class _SearchFiltersState extends State<SearchFilters> {
var _propType = ["Free Standing", "Town House", "Apartment", "Vacant Land", "Ofiice", "Farm", "New Development"];
var _currentItemPropery = "Free Standing";
var _town = ["Rehoboth", "Windhoek", "Swakopmund", "Walvisbay", "Keetmanshoop", "Otjiwarongo"];
var _currentItemTown = "Rehoboth";
var _minPrice = ["N\$ 10.00", "N\$ 20.00", "N\$ 30.00", "N\$ 40.00", "N\$ 50.00"];
var _currentItemMinPrice = "N\$ 10.00";
var _maxPrice = ["N\$ 100.00", "N\$ 200.00", "N\$ 300.00", "N\$ 400.00", "N\$ 500.00"];
var _currentItemMaxPrice = "N\$ 100.00";
var _minBeds = ["1", "2"];
var _currentItemMinBeds = "1";
var _maxBeds = ["1", "2", "3", "4", "5"];
var _currentItemMaxBeds = "1";
var _baths = ["1", "2", "3", "4", "5"];
var _currentItemBaths = "1";
var _parking = ["1", "2", "3"];
var _currentItemParking = "1";
#override
Widget build(BuildContext context) {
return Flexible(
child: ListView(
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: <Widget>[
Container(
// height: MediaQuery.of(context).size.height,
child: Column(
children: <Widget>[
// todo =========== Property Type =====================
Container(
margin: EdgeInsets.only(left: 24.0, right: 24.0),
alignment: Alignment.centerLeft,
child: Text(
"Property Type",
style: TextStyle(
color: Colors.grey,
fontSize: 18.0,
fontStyle: FontStyle.italic,
),
)),
SizedBox(height: 12.0),
Container(
margin: EdgeInsets.only(left: 40.0, right: 40.0),
padding: EdgeInsets.only(left: 24.0, right: 24.0),
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
width: 2.0,
style: BorderStyle.solid,
color: Color(0xFFFA983A)),
borderRadius: BorderRadius.all(Radius.circular(12.0)),
),
),
child: DropdownButton<String>(
items: _propType.map((String dropDownStringItem) {
return DropdownMenuItem<String>(
value: dropDownStringItem,
child: Text(
dropDownStringItem,
style: TextStyle(color: Colors.black),
),
);
}).toList(),
onChanged: (String newValueSelected) {
setState(() {
this._currentItemPropery = newValueSelected;
});
},
value: _currentItemPropery,
style: TextStyle(fontSize: 18),
iconSize: 40.0,
isExpanded: true,
),
),
SizedBox(
height: 12.0,
),
// todo =========== Towns =====================
Container(
margin: EdgeInsets.only(left: 24.0, right: 24.0),
alignment: Alignment.centerLeft,
child: Text(
"Town",
style: TextStyle(
color: Colors.grey,
fontSize: 18.0,
fontStyle: FontStyle.italic,
),
),
),
SizedBox(height: 12.0),
Container(
margin: EdgeInsets.only(left: 40.0, right: 40.0),
padding: EdgeInsets.only(left: 24.0, right: 24.0),
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
width: 2.0,
style: BorderStyle.solid,
color: Color(0xFFFA983A)),
borderRadius: BorderRadius.all(Radius.circular(12.0)),
),
),
child: DropdownButton<String>(
items: _town.map((String dropDownStringItem) {
return DropdownMenuItem<String>(
value: dropDownStringItem,
child: Text(
dropDownStringItem,
style: TextStyle(color: Colors.black),
),
);
}).toList(),
onChanged: (String newValueSelected) {
setState(() {
this._currentItemTown = newValueSelected;
});
},
value: _currentItemTown,
style: TextStyle(fontSize: 18),
iconSize: 40.0,
isExpanded: true,
),
),
SizedBox(
height: 12.0,
),
// todo =========== Min Price =====================
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 24.0),
alignment: Alignment.centerLeft,
child: Text(
"Min Price",
style: TextStyle(
color: Colors.grey,
fontSize: 18.0,
fontStyle: FontStyle.italic,
),
),
),
Container(
margin: EdgeInsets.only(right: 40.0),
padding: EdgeInsets.only(left: 24.0, right: 24.0),
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
width: 2.0,
style: BorderStyle.solid,
color: Color(0xFFFA983A)),
borderRadius: BorderRadius.all(Radius.circular(12.0)),
),
),
child: DropdownButton<String>(
items: _minPrice.map((String dropDownStringItem) {
return DropdownMenuItem<String>(
value: dropDownStringItem,
child: Text(
dropDownStringItem,
style: TextStyle(color: Colors.black),
),
);
}).toList(),
onChanged: (String newValueSelected) {
setState(
() {
this._currentItemMinPrice = newValueSelected;
},
);
},
value: _currentItemMinPrice,
style: TextStyle(fontSize: 18),
iconSize: 40.0,
// isExpanded: true,
),
),
],
),
SizedBox(height: 12.0),
// todo =========== Max Price =====================
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 24.0),
alignment: Alignment.centerLeft,
child: Text(
"Max Price",
style: TextStyle(
color: Colors.grey,
fontSize: 18.0,
fontStyle: FontStyle.italic,
),
),
),
Container(
margin: EdgeInsets.only(right: 40.0),
padding: EdgeInsets.only(left: 24.0, right: 24.0),
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
width: 2.0,
style: BorderStyle.solid,
color: Color(0xFFFA983A)),
borderRadius: BorderRadius.all(Radius.circular(12.0)),
),
),
child: DropdownButton<String>(
items: _maxPrice.map((String dropDownStringItem) {
return DropdownMenuItem<String>(
value: dropDownStringItem,
child: Text(
dropDownStringItem,
style: TextStyle(color: Colors.black),
),
);
}).toList(),
onChanged: (String newValueSelected) {
setState(
() {
this._currentItemMaxPrice = newValueSelected;
},
);
},
value: _currentItemMaxPrice,
style: TextStyle(fontSize: 18),
iconSize: 40.0,
// isExpanded: true,
),
),
],
),
SizedBox(height: 12.0),
// todo ================== Min Bedrooms =====================
Row(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width / 2,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 24.0, right: 24.0),
alignment: Alignment.centerLeft,
child: Text(
"Min Bedrooms",
style: TextStyle(
color: Colors.grey,
fontSize: 18.0,
fontStyle: FontStyle.italic,
),
),
),
SizedBox(height: 12.0),
Container(
margin: EdgeInsets.only(left: 40.0, right: 40.0),
padding: EdgeInsets.only(left: 24.0, right: 24.0),
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
width: 2.0,
style: BorderStyle.solid,
color: Color(0xFFFA983A)),
borderRadius:
BorderRadius.all(Radius.circular(12.0)),
),
),
child: DropdownButton<String>(
items: _minBeds.map((String dropDownStringItem) {
return DropdownMenuItem<String>(
value: dropDownStringItem,
child: Text(
dropDownStringItem,
style: TextStyle(color: Colors.black),
),
);
}).toList(),
onChanged: (String newValueSelected) {
setState(() {
this._currentItemMinBeds = newValueSelected;
});
},
value: _currentItemMinBeds,
style: TextStyle(fontSize: 18),
iconSize: 40.0,
isExpanded: true,
),
),
],
),
),
// todo ================== Max Bedrooms =====================
Container(
width: MediaQuery.of(context).size.width / 2,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 24.0, right: 24.0),
alignment: Alignment.centerLeft,
child: Text(
"Max Bedrooms",
style: TextStyle(
color: Colors.grey,
fontSize: 18.0,
fontStyle: FontStyle.italic,
),
),
),
SizedBox(height: 12.0),
Container(
margin: EdgeInsets.only(left: 40.0, right: 40.0),
padding: EdgeInsets.only(left: 24.0, right: 24.0),
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
width: 2.0,
style: BorderStyle.solid,
color: Color(0xFFFA983A)),
borderRadius:
BorderRadius.all(Radius.circular(12.0)),
),
),
child: DropdownButton<String>(
items: _maxBeds.map((String dropDownStringItem) {
return DropdownMenuItem<String>(
value: dropDownStringItem,
child: Text(
dropDownStringItem,
style: TextStyle(color: Colors.black),
),
);
}).toList(),
onChanged: (String newValueSelected) {
setState(() {
this._currentItemMaxBeds = newValueSelected;
});
},
value: _currentItemMaxBeds,
style: TextStyle(fontSize: 18),
iconSize: 40.0,
isExpanded: true,
),
),
],
),
),
],
),
SizedBox(height: 12.0),
// todo ================== Bathrooms =====================
Row(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width / 2,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 24.0, right: 24.0),
alignment: Alignment.centerLeft,
child: Text(
"Bathrooms",
style: TextStyle(
color: Colors.grey,
fontSize: 18.0,
fontStyle: FontStyle.italic,
),
),
),
SizedBox(height: 12.0),
Container(
margin: EdgeInsets.only(left: 40.0, right: 40.0),
padding: EdgeInsets.only(left: 24.0, right: 24.0),
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
width: 2.0,
style: BorderStyle.solid,
color: Color(0xFFFA983A)),
borderRadius:
BorderRadius.all(Radius.circular(12.0)),
),
),
child: DropdownButton<String>(
items:
_baths.map((String dropDownStringItem) {
return DropdownMenuItem<String>(
value: dropDownStringItem,
child: Text(
dropDownStringItem,
style: TextStyle(color: Colors.black),
),
);
}).toList(),
onChanged: (String newValueSelected) {
setState(() {
this._currentItemBaths = newValueSelected;
});
},
value: _currentItemBaths,
style: TextStyle(fontSize: 18),
iconSize: 40.0,
isExpanded: true,
),
),
],
),
),
// todo ================== Parking =====================
Container(
width: MediaQuery.of(context).size.width / 2,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 24.0, right: 24.0),
alignment: Alignment.centerLeft,
child: Text(
"Car Spaces",
style: TextStyle(
color: Colors.grey,
fontSize: 18.0,
fontStyle: FontStyle.italic,
),
),
),
SizedBox(height: 12.0),
Container(
margin: EdgeInsets.only(left: 40.0, right: 40.0),
padding: EdgeInsets.only(left: 24.0, right: 24.0),
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
width: 2.0,
style: BorderStyle.solid,
color: Color(0xFFFA983A)),
borderRadius:
BorderRadius.all(Radius.circular(12.0)),
),
),
child: DropdownButton<String>(
items:
_parking.map((String dropDownStringItem) {
return DropdownMenuItem<String>(
value: dropDownStringItem,
child: Text(
dropDownStringItem,
style: TextStyle(color: Colors.black),
),
);
}).toList(),
onChanged: (String newValueSelected) {
setState(() {
this._currentItemParking = newValueSelected;
});
},
value: _currentItemParking,
style: TextStyle(fontSize: 18),
iconSize: 40.0,
isExpanded: true,
),
),
],
),
),
],
),
SizedBox(height: 24.0),
// todo ================= Mail Button ====================
Container(
margin: EdgeInsets.only(left: 40, right: 40),
child: ButtonTheme(
minWidth: MediaQuery.of(context).size.width,
height: 50,
splashColor: Colors.white30,
child: RaisedButton(
elevation: 5.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
onPressed: () {},
padding: EdgeInsets.all(0.0),
color: Color(0xFFFA983A),
child: Text(
"SEARCH",
style: TextStyle(
color: Colors.white,
),
),
),
),
),
SizedBox(height: 24.0),
],
),
),
],
),
);
}
}```

Assuming you are decoding the json as shown above, you need to use something like:
void parseJson() async {
var decode = json.decode(theJson);
var types = decode[0]['prop_type']; // List<dynamic>
_propTypes = List<String>.from(types); // List<String>
...
setState((){});
}
(Prefer camelCase for variable names.)
List.from is a handy way to change the type of a list. Remember that the whole structure of json where the right hand side of a value can be a bool, int, string, array, object means that the json decoder has to make things dynamic in Dart.
Now your map to create items should work.

Related

Border around DropdownMenu

I want to give border to DropdownButton and DropdownMenu like below image along with height itemHeight of 21px and some background color to DropdownMenuItem on mouse hover and on keyboard up or down keys:
Here is what I have tried till now:
var genderList = [
'Female',
'Male',
'Other',
];
String? selection;
final border = const OutlineInputBorder(
borderSide: BorderSide(
width: 1,
color: Color(0xFF00AFEF),
),
borderRadius: BorderRadius.all(Radius.circular(7)),
);
...
SizedBox(
height: 38.h,
// color: Colors.blue,
child: InputDecorator(
decoration: InputDecoration(
contentPadding: EdgeInsets.zero,
border: border,
enabledBorder: border,
),
child: DropdownButtonHideUnderline(
child: DropdownButton(
isExpanded: true,
hint: Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 13.w),
child: const Text(
'Gender',
style: TextStyle(
fontSize: 14,
color: Color(0xFF606060),
),
),
),
),
value: selection,
icon: Container(
margin: EdgeInsets.symmetric(horizontal: 13.w),
height: 10.r,
width: 16.r,
alignment: Alignment.center,
child: SvgPicture.asset(
AppIcons.arrowDown,
),
),
onChanged: (String? val) {
setState(() => selection = val);
},
items: genderList.map((option) {
return DropdownMenuItem(
value: option,
child: Container(
width: double.infinity,
height: 21.h,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color(0xFFCBF1FF),
border: Border.all(
color: Color(0xFF00AFEF), width: 1)),
child: Text(
option,
style: TextStyle(
fontSize: 12,
color: Color(0xFF606060),
),
),
),
);
}).toList(),
selectedItemBuilder: (con) {
return genderList.map((val) {
return Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: EdgeInsets.only(left: 13.w),
child: Text(
val,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 14,
color: Color(0xFF606060),
),
),
),
);
}).toList();
},
),
),
),
);
What I got,
DropDownButton:
DropdownMenu:
How can I get the desired design?
I was able to get the desired result using dropdown_button2
You can use dropdownXXXX parameters for editing related dropdown menu properties.
Only issue I find is that when giving dropdown menu border some radius its covered by selectedItemHighlightColor. So I have used some padding to overcome it.
SizedBox(
height: 38,
child: InputDecorator(
decoration: InputDecoration(
contentPadding: EdgeInsets.zero,
border: border,
enabledBorder: border,
),
child: DropdownButtonHideUnderline(
child: DropdownButton2(
selectedItemHighlightColor: AppColors.lightBackground,
itemHighlightColor: AppColors.lightBackground,
dropdownDecoration: BoxDecoration(
border: Border.all(
color: AppColors.primary,
width: 1,
),
borderRadius: BorderRadius.circular(4),
),
dropdownElevation: 0,
dropdownPadding: const EdgeInsets.symmetric(
horizontal: 1.5,
vertical: 1.5,
),
itemPadding: EdgeInsets.zero,
customItemsHeights: [21, 21, 21],
isExpanded: true,
hint: const Padding(
padding: EdgeInsets.symmetric(horizontal: 14),
child: Text(
'Gender',
style: TextStyle(
fontSize: 14,
color: AppColors.secondaryText,
),
),
),
value: widget.value,
icon: Container(
margin: const EdgeInsets.symmetric(horizontal: 14),
height: 10,
width: 16,
alignment: Alignment.center,
child: SvgPicture.asset(
AppIcons.arrowDown,
),
),
onChanged: widget.onChanged,
items: widget.list.map((option) {
return DropdownMenuItem(
value: option,
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 14),
child: Text(
option,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: AppColors.secondaryText,
),
),
),
);
}).toList(),
selectedItemBuilder: (con) {
return widget.list.map((val) {
return Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.only(left: 14),
child: Text(
val,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 14,
color: AppColors.secondaryText,
),
),
),
);
}).toList();
},
),
),
),
);

How to allow user to Tap header to open on ExpansionPanel

I have built a help / FAQ screen within my flutter app. Using expansion tile I have created the UI but I am having issues with tapping the header.
I'm wanting to allow the user to tap the header to open that tile. Currently, the user has to tap the arrow to open.
I have added "canTapOnHeader: true," but that does not seem to work. I've searched Stackoverflow but still had no luck
Any help would be great!
ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Text(
itemData[index].headerItem,
style: TextStyle(
color: Theme.of(context).accentColor,
fontSize: 17,
),
),
),
),
],
);
},
body: Container(
padding: EdgeInsets.only(left: 10, right: 10, bottom: 30),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Image.asset(
itemData[index].img,
fit: BoxFit.cover,
),
SizedBox(height: 10),
Divider(
thickness: 3.0,
height: 3.0,
color: Theme.of(context).accentColor,
indent: 10,
endIndent: 300),
Padding(
padding: const EdgeInsets.only(left: 8.0, top: 10),
child: Text(
itemData[index].description,
style: TextStyle(
color: Theme.of(context).accentColor,
fontSize: 15,
height: 1.3,
),
),
),
],
),
),
canTapOnHeader: true,
isExpanded: itemData[index].expanded,
)
],
expansionCallback: (int item, bool status) {
setState(() {
itemData[index].expanded = !itemData[index].expanded;
});
},
),
);
},
),
),
);}
List<ItemModel> itemData = <ItemModel>[
ItemModel(
headerItem: 'This is a header question?',
description:
"This is the description for the question.",
img: 'assets/images/typingtextgiphy.gif',
),
];
}
class ItemModel {
bool expanded;
String headerItem;
String description;
String img;
ItemModel({
this.expanded: false,
this.headerItem,
this.description,
this.img,
});
}
Managed to find the solution for this. Here's the code, can copy and paste
class _HelpPanelState extends State<HelpPanel> {
#override
Widget build(BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: BackButton(
color: Theme.of(context).accentColor,
),
title: Text(AppLocalizations.of(context)!.tutorial,
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 20.0,
color: Theme.of(context).colorScheme.primary)),
elevation: 0.0,
),
body: SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Card(
elevation: 3,
shape: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide: BorderSide(color: Colors.white)),
child: Padding(
padding: EdgeInsets.only(
top: 0.0, left: 15.0, right: 15.0, bottom: 0.0),
child: ExpansionTile(
title: Text(
"QUESTION",
style: GoogleFonts.roboto(
textStyle: TextStyle(
fontWeight: FontWeight.w900,
fontSize: 20,
color: Theme.of(context).accentColor,
letterSpacing: 0.4,
),
),
textAlign: TextAlign.left,
),
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Image(
image: AssetImage(
'assets/images/typingautoverse.gif',
),
),
),
),
SizedBox(height: 5),
Padding(
padding:
const EdgeInsets.only(left: 15.0, bottom: 10),
child: Text(
"ANSWER",
style: GoogleFonts.roboto(
textStyle: TextStyle(
fontWeight: FontWeight.w300,
fontSize: 20,
color: Theme.of(context).accentColor,
letterSpacing: 0.4,
height: 1.3,
),
),
),
),
],
),
),
),
),
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Card(
elevation: 3,
shape: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide: BorderSide(color: Colors.white)),
child: Padding(
padding: EdgeInsets.only(
top: 0.0, left: 15.0, right: 15.0, bottom: 0.0),
child: ExpansionTile(
title: Text(
"QUESTION",
style: GoogleFonts.roboto(
textStyle: TextStyle(
fontWeight: FontWeight.w900,
fontSize: 20,
color: Theme.of(context).accentColor,
letterSpacing: 0.4,
),
),
textAlign: TextAlign.left,
),
children: <Widget>[
Padding(
padding:
const EdgeInsets.only(left: 15.0, bottom: 10),
child: Text(
"ANSWER"
style: GoogleFonts.roboto(
textStyle: TextStyle(
fontWeight: FontWeight.w300,
fontSize: 20,
color: Theme.of(context).accentColor,
letterSpacing: 0.4,
height: 1.3,
),
),
),
),
],
),
),
),
),
],
),
),
),
),
);
}
}

How to add scroll on visibility on flutter

i want to make scrollview in visibility but when i try to add SingleChildScrollView it still doesn't work, the result is like this
This is the result
and what I want the application will run as shown below
its main purpose is when the DropdownMenuItem is scrolled on the screen it will not be carried away
thank you, sorry if my words are a little difficult to understand
and this is my code:
class AddressScreen extends StatefulWidget {
#override
State<StatefulWidget> createState() => _AddressState();
}
class _AddressState extends State<AddressScreen> {
String? _detail;
bool _saveButton = false;
String? valueChoose;
List listProvinsi = ['Lampung', 'DKI Jakarta'];
String? valueChoose2;
List listKabupaten = ['Bandar Lampung', 'Jakarta Timur'];
String? valueChoose3;
List listKecamatan = ['Kemiling', 'Cipayung'];
String? valueChoose4;
List listKelurahan = ['Beringin Raya', 'Bambu Apus'];
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[100],
appBar: AppBar(
titleSpacing: 0,
elevation: 10,
backgroundColor: Theme.of(context).primaryColor,
title: Text(
'Alamat',
style: TextStyle(fontSize: 18),
),
actions: [
GestureDetector(
onTap: () => {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProfileScreen(),
),
),
},
child: Container(
height: 30,
width: 30,
margin: EdgeInsets.only(
right: 3,
),
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Colors.white, width: 1.5),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(personImg),
),
),
),
),
GestureDetector(
onTap: () => {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomeScreen(),
),
),
},
child: Container(
margin: EdgeInsets.only(
right: 7,
),
child: Image.asset(iconAppbar),
),
),
],
),
body: SafeArea(
child: Container(
child: Column(
children: <Widget>[
Container(
height: SizeConfig.screenHeight / 4.5,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Color(0x14000000),
offset: Offset(
0,
2,
),
blurRadius: 4,
spreadRadius: 2,
),
],
),
child: Row(
children: [
SizedBox(width: SizeConfig.screenWidth / 17),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 15),
Container(
child: Text(
'Alamat Anda',
style: TextStyle(
color: Colors.grey.shade700,
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
),
Container(
height: SizeConfig.screenHeight / 9,
width: SizeConfig.screenWidth / 2.2,
// color: Colors.grey,
child: Row(
children: [
Expanded(
child: Text(
'Perumahan Berkoh Indah Jl. Brawijaya No. 45 Gg. Mangga Rt.03 Rw.05 Kel. Arcawinangun, Kec. Purwokerto Timur, Kab. Banyumas Jawa Tengah - 53114',
style: TextStyle(
color: Colors.black54,
fontSize: 11,
),
),
),
],
),
)
],
),
SizedBox(width: SizeConfig.screenWidth / 9),
//#arjunalst2020
// ChangeButton(),
InkWell(
onTap: () {
setState(() {
_saveButton = !_saveButton;
});
},
child: Container(
margin:
EdgeInsets.only(top: SizeConfig.screenHeight / 8),
height: SizeConfig.screenHeight / 17,
width: SizeConfig.screenWidth / 3,
decoration: _saveButton
? BoxDecoration(
color: Colors.grey.shade700,
borderRadius:
BorderRadius.all(Radius.circular(8)))
: BoxDecoration(
color: Colors.pink.shade800,
borderRadius:
BorderRadius.all(Radius.circular(8))),
child: Center(
child: Text(
_saveButton ? 'Simpan' : 'Ubah',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
),
),
],
),
),
SizedBox(height: 20),
Visibility(
visible: _saveButton,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Provinsi',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Container(
height: SizeConfig.screenHeight / 17,
padding: EdgeInsets.only(right: 10, left: 10),
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: DropdownButton(
isExpanded: true,
dropdownColor: Colors.white,
value: valueChoose,
iconSize: 25,
underline: SizedBox(),
style: TextStyle(
fontSize: 13,
color: Colors.black54,
fontWeight: FontWeight.bold),
onChanged: (newValue) {
setState(() {
valueChoose = newValue.toString();
});
},
items: listProvinsi.map((valueItem) {
return DropdownMenuItem(
value: valueItem, child: Text(valueItem));
}).toList(),
),
),
),
),
SizedBox(height: 30),
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Kabupaten/Kota',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Container(
height: SizeConfig.screenHeight / 17,
padding: EdgeInsets.only(right: 10, left: 10),
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: DropdownButton(
isExpanded: true,
dropdownColor: Colors.white,
value: valueChoose2,
iconSize: 25,
underline: SizedBox(),
style: TextStyle(
fontSize: 13,
color: Colors.black54,
fontWeight: FontWeight.bold),
onChanged: (newValue2) {
setState(() {
valueChoose2 = newValue2.toString();
});
},
items: listKabupaten.map((valueItem) {
return DropdownMenuItem(
value: valueItem, child: Text(valueItem));
}).toList(),
),
),
),
),
SizedBox(height: 30),
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Kecamatan',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Container(
height: SizeConfig.screenHeight / 17,
padding: EdgeInsets.only(right: 10, left: 10),
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: DropdownButton(
isExpanded: true,
dropdownColor: Colors.white,
value: valueChoose3,
iconSize: 25,
underline: SizedBox(),
style: TextStyle(
fontSize: 13,
color: Colors.black54,
fontWeight: FontWeight.bold),
onChanged: (newValue3) {
setState(() {
valueChoose3 = newValue3.toString();
});
},
items: listKecamatan.map((valueItem) {
return DropdownMenuItem(
value: valueItem, child: Text(valueItem));
}).toList(),
),
),
),
),
SizedBox(height: 30),
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Kelurahan',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Container(
height: SizeConfig.screenHeight / 17,
padding: EdgeInsets.only(right: 10, left: 10),
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: DropdownButton(
isExpanded: true,
dropdownColor: Colors.white,
value: valueChoose4,
iconSize: 25,
underline: SizedBox(),
style: TextStyle(
fontSize: 13,
color: Colors.black54,
fontWeight: FontWeight.bold,
),
onChanged: (newValue4) {
setState(() {
valueChoose4 = newValue4.toString();
});
},
items: listKelurahan.map((valueItem) {
return DropdownMenuItem(
value: valueItem, child: Text(valueItem));
}).toList(),
),
),
),
),
SizedBox(height: 30),
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Jalan/Gang/Nama Gedung/Nama Perumahan',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Container(
height: SizeConfig.screenHeight / 17,
width: SizeConfig.screenWidth / 1.12,
child: TextField(
maxLines: 1,
style: TextStyle(fontSize: 12),
onChanged: (value) {
setState(() {
_detail = value;
});
},
decoration: InputDecoration(
counterText: "",
fillColor: Colors.grey.shade300,
filled: true,
border: OutlineInputBorder(
borderSide: BorderSide.none,
),
),
),
),
),
SizedBox(height: 30),
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Unit/Blok/RT/RW',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Container(
height: SizeConfig.screenHeight / 17,
width: SizeConfig.screenWidth / 1.12,
child: TextField(
maxLines: 1,
style: TextStyle(fontSize: 12),
onChanged: (value) {
setState(() {
_detail = value;
});
},
decoration: InputDecoration(
fillColor: Colors.grey.shade300,
filled: true,
border: OutlineInputBorder(
borderSide: BorderSide.none,
),
),
),
),
),
SizedBox(height: 30),
Container(
margin: EdgeInsets.only(left: 23),
child: Text(
'Kode Pos',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 12,
),
),
),
SizedBox(height: 3),
Center(
child: Container(
height: SizeConfig.screenHeight / 17,
width: SizeConfig.screenWidth / 1.12,
child: TextField(
keyboardType: TextInputType.number,
maxLines: 1,
maxLength: 8,
style: TextStyle(fontSize: 12),
onChanged: (value) {
setState(() {
_detail = value;
});
},
decoration: InputDecoration(
fillColor: Colors.grey.shade300,
filled: true,
counterText: "",
border: OutlineInputBorder(
borderSide: BorderSide.none,
),
),
),
),
),
SizedBox(height: 30),
Center(
child: Container(
width: SizeConfig.screenWidth / 1.12,
height: SizeConfig.screenHeight / 10,
decoration: BoxDecoration(
color: Colors.transparent,
border:
Border.all(color: Colors.black38, width: 0.6),
),
child: Row(
children: [
Container(
height: SizeConfig.screenHeight,
width: SizeConfig.screenWidth / 5,
decoration: BoxDecoration(
color: Colors.blueGrey,
),
child: Icon(
Icons.location_on,
color: Colors.white,
size: 35,
),
),
SizedBox(width: SizeConfig.screenWidth / 20),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 10),
Text(
'Tandai Lokasi Peta',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
fontSize: 11,
),
),
Container(
height: SizeConfig.screenHeight / 17,
width: SizeConfig.screenWidth / 1.9,
child: Row(
children: [
Expanded(
child: Text(
'Jl. Brawijaya No,45 Gg. Mangga Kel. Arcawinangun, Kec. Purwokerto Timur, Banyumas',
style: TextStyle(
fontSize: 11,
color: Colors.grey.shade800,
),
),
),
],
),
),
],
),
],
),
),
),
SizedBox(height: 10),
Container(
height: SizeConfig.screenHeight / 20,
width: SizeConfig.screenWidth / 1.6,
margin:
EdgeInsets.only(left: SizeConfig.screenWidth / 3.3),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Text(
'Pastikan lokasi yang Anda tandai di peta sesuai dengan alamat yang Anda isi di atas',
style: TextStyle(
fontSize: 9,
color: Colors.grey.shade800,
),
),
),
],
),
),
SizedBox(height: 30),
],
),
),
),
],
),
),
),
);
}
}
I'm sorry if my code is still messy or a lot of it is not effective, I'm just learning 😅
Wrap the Visibility widget with Expanded.
Expanded(
child: Visibility(
.....
),
),
If this doesn't work, wrap the main body Column with SingleChildScrollView.
NOTE: Wrapping the main Column with a Container is unnecessary.
I had the same issue multiple times.
you need to wrap your SingleChildScrollView in a Flexible.
Here is the sequence I need to do to always fix:
Flexible(
child: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
children:[Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(left:10, top: 20, bottom: 20),
child: Text( )

Flutter - custom toggle buttons selection

I am building a row of toggle buttons (on/off selectors) which is basically a row of containers and each container is a category and is clickable.
Q: How to make it so in a way when one category is selected all the others get deselected?
This is the categories widget I've build:
Widget header(){
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 4.0, left: 0.0, right: 0.0, bottom: 6.0),
child: Container(
child: Center(
child: Column(
children: <Widget>[
SizedBox(height: 4.0,),
Container(
margin: EdgeInsets.only(left: 10.0, right: 10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
InkWell(
splashColor: Colors.blue[100],
onTap: (){},
child: Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.blueAccent[100],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('All',
style: TextStyle(color: Colors.white, fontSize: 10.0, fontWeight: FontWeight.w500),),
),
),
SizedBox(width: 2.0,),
InkWell(
splashColor: Colors.blue[100],
onTap: (){},
child: Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('category 1',
style: TextStyle(color: Colors.grey[900], fontSize: 10.0, fontWeight: FontWeight.w500),),
),
),
SizedBox(width: 2.0,),
InkWell(
splashColor: Colors.blue[100],
onTap: (){},
child: Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('category 2',
style: TextStyle(color: Colors.grey[900], fontSize: 10.0, fontWeight: FontWeight.w500),),
),
),
SizedBox(width: 2.0,),
InkWell(
splashColor: Colors.blue[100],
onTap: (){},
child: Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('category 3',
style: TextStyle(color: Colors.grey[900], fontSize: 10.0, fontWeight: FontWeight.w500),),
),
),
SizedBox(width: 2.0,),
InkWell(
splashColor: Colors.blue[100],
onTap: (){},
child: Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('category 4',
style: TextStyle(color: Colors.grey[900], fontSize: 10.0, fontWeight: FontWeight.w500),),
),
),
],
),
),
SizedBox(height: 6.0,)
],
),
),
),
),
],
);
}`
The best way would be to use ListView.builder to build your items and save the selected indexes but you can also modify your existing code to save selected items in a list and check to see if the item is in the list and if it is then add selection format and refresh the page. You can implement that as shown below,
class MyApp extends StatefulWidget {
#override
MyAppState createState() => MyAppState();
}
class MyAppState extends State<MyApp> {
List<String> selectedCategory = new List<String>();
String all = 'All';
String category1 = 'category 1';
String category2 = 'category 2';
String category3 = 'category 3';
String category4 = 'category 4';
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Test'),
),
body: Container(
padding: const EdgeInsets.all(20.0),
child: header()
)));
}
Widget header(){
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 4.0, left: 0.0, right: 0.0, bottom: 6.0),
child: Container(
child: Center(
child: Column(
children: <Widget>[
SizedBox(height: 4.0,),
Container(
margin: EdgeInsets.only(left: 10.0, right: 10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
InkWell(
splashColor: Colors.blue[100],
onTap: (){
selectedCategory.add(all);
selectedCategory.add(category1);
selectedCategory.add(category2);
selectedCategory.add(category3);
selectedCategory.add(category4);
setState(() {});
},
child: Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: selectedCategory.contains(all) ? Colors.blueAccent[100] : Colors.grey[500],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('All',
style: TextStyle(color: Colors.white, fontSize: 10.0, fontWeight: FontWeight.w500),),
),
),
SizedBox(width: 2.0,),
InkWell(
splashColor: Colors.blue[100],
onTap: (){
selectedCategory = new List<String>();
selectedCategory.add(category1);
setState(() {});
},
child: Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: selectedCategory.contains(category1) ? Colors.blue[100] : Colors.grey[300],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('category 1',
style: TextStyle(color: Colors.grey[900], fontSize: 10.0, fontWeight: FontWeight.w500),),
),
),
SizedBox(width: 2.0,),
InkWell(
splashColor: Colors.blue[100],
onTap: (){
selectedCategory = new List<String>();
selectedCategory.add(category2);
setState(() {});
},
child: Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: selectedCategory.contains(category2) ? Colors.blue[100] : Colors.grey[300],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('category 2',
style: TextStyle(color: Colors.grey[900], fontSize: 10.0, fontWeight: FontWeight.w500),),
),
),
SizedBox(width: 2.0,),
InkWell(
splashColor: Colors.blue[100],
onTap: (){
selectedCategory = new List<String>();
selectedCategory.add(category3);
setState(() {});
},
child: Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: selectedCategory.contains(category3) ? Colors.blue[100] : Colors.grey[300],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('category 3',
style: TextStyle(color: Colors.grey[900], fontSize: 10.0, fontWeight: FontWeight.w500),),
),
),
SizedBox(width: 2.0,),
InkWell(
splashColor: Colors.blue[100],
onTap: (){
selectedCategory = new List<String>();
selectedCategory.add(category4);
setState(() {});
},
child: Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: selectedCategory.contains(category4) ? Colors.blue[100] : Colors.grey[300],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('category 4',
style: TextStyle(color: Colors.grey[900], fontSize: 10.0, fontWeight: FontWeight.w500),),
),
),
],
),
),
SizedBox(height: 6.0,)
],
),
),
),
),
],
);
}
}
Hope this helps.
Well, this piece of code can be optimized, but so far this worked just fine:
class Header extends StatefulWidget {
#override
_HeaderState createState() => _HeaderState();
}
class _HeaderState extends State<Header> {
List<bool> isSelected;
#override
void initState() {
isSelected = [true, false, false, false, false];
super.initState();
}
#override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
ToggleButtons(
borderColor: Colors.transparent,
fillColor: Colors.transparent,
borderWidth: null,
selectedBorderColor: Colors.transparent,
selectedColor: Colors.transparent,
splashColor: Colors.transparent,
children: <Widget>[
!isSelected[0] ?
Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
margin: EdgeInsets.only(right: 3.0),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('cat 1',
style: TextStyle(color: Colors.grey[900], fontSize: 10.0, fontWeight: FontWeight.w500),),
)
:Container(
margin: EdgeInsets.only(right: 3.0),
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.blueAccent[100],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('cat 1',
style: TextStyle(color: Colors.white, fontSize: 10.0, fontWeight: FontWeight.w700),),
),
!isSelected[1] ?
Container(
margin: EdgeInsets.only(right: 3.0),
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('cat 2',
style: TextStyle(color: Colors.grey[900], fontSize: 10.0, fontWeight: FontWeight.w500),),
)
:Container(
margin: EdgeInsets.only(right: 3.0),
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.blueAccent[100],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('cat 2',
style: TextStyle(color: Colors.white, fontSize: 10.0, fontWeight: FontWeight.w700),),
),
!isSelected[2] ?
Container(
margin: EdgeInsets.only(right: 3.0),
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('cat 3',
style: TextStyle(color: Colors.grey[900], fontSize: 10.0, fontWeight: FontWeight.w500),),
)
:Container(
margin: EdgeInsets.only(right: 3.0),
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.blueAccent[100],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('cat 3',
style: TextStyle(color: Colors.white, fontSize: 10.0, fontWeight: FontWeight.w700),),
),
!isSelected[3] ?
Container(
margin: EdgeInsets.only(right: 3.0),
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('cat 4',
style: TextStyle(color: Colors.grey[900], fontSize: 10.0, fontWeight: FontWeight.w500),),
)
:Container(
margin: EdgeInsets.only(right: 3.0),
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.blueAccent[100],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('cat 4',
style: TextStyle(color: Colors.white, fontSize: 10.0, fontWeight: FontWeight.w700),),
),
!isSelected[4] ?
Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('cat 5',
style: TextStyle(color: Colors.grey[900], fontSize: 10.0, fontWeight: FontWeight.w500),),
)
:Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 12.0),
decoration: BoxDecoration(
color: Colors.blueAccent[100],
borderRadius: BorderRadius.all(Radius.circular(48.0)),
),
child: Text('cat 5',
style: TextStyle(color: Colors.white, fontSize: 10.0, fontWeight: FontWeight.w700),),
),
],
onPressed: (int index) {
setState(() {
for (int i = 0; i < isSelected.length; i++) {
isSelected[i] = i == index;
}
});
},
isSelected: isSelected,
),
],
);
}
}

trigger flutter IconButton ripple animation programmtically?

Is there a way to programmatically trigger the IconButton ripple animation? The following is some code:
#override
Widget build(BuildContext context) {
return Material(
child: Container(
margin: EdgeInsets.only(top: 12, left: 18, right: 18),
padding: EdgeInsets.only(top: 8, bottom: 8),
decoration: BoxDecoration(
color: _bgColor,
border: new Border.all(color: _bgColor),
borderRadius: BorderRadius.all(Radius.circular(
10.0) // <--- border radius here
),
),
child: Row(children: [
IconButton(
padding: EdgeInsets.only(right: 16),
icon: Icon(Icons.play_arrow, color: Colors.white, size: 48),
tooltip: 'Start ${issue.issueName}',
onPressed: () {},
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
issue.title,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
softWrap: true,
),
),
Text(
issue.issueName,
style: TextStyle(
color: Colors.white,
),
),
],
),
),
])));
}