I am selecting the count of son, on the basis of count I created selected number of dropdown I just want to get value from each dropdown dropdown and dropdown count is not fixed. So I want separate value from each dropdown. How can I achieve this.
bool sonVisible = false;
bool sonChecked = false;
String sonCount;
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: CustomListTile(
title: 'Son',
selected: sonChecked,
onChanged: (bool value) {
setState(() {
sonChecked = value;
if (sonChecked == true) {
sonVisible = true;
} else {
sonVisible = false;
sonDropDown = false;
}
});
},
)),
Flexible(
child: Visibility(
visible: sonVisible,
child: CustomCountDropDown(
ageValue: sonCount,
onChanged: (val) {
setState(() {
sonCount = val;
sonListCount = int.parse(sonCount);
print(sonCount);
sonDropDown = true;
});
},
decoration: spinnerDecoration('No of Son'),
),
)),
],
),
Visibility(
visible: sonDropDown,
maintainState: true,
child: Padding(
padding: EdgeInsets.only(top: 1.0.h, left: 3.0.h),
child: GridView.builder(
itemCount: sonListCount,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 4.0.w,
childAspectRatio: MediaQuery.of(context)
.size
.width /
(MediaQuery.of(context).size.height / 5),
),
shrinkWrap: true,
itemBuilder: (context, index) {
return CustomAgeDropDown(
decoration: spinnerDecoration(
'Age Son - ${index + 1}'),
ageValue: (how can I get value ?),
onChanged: (value) {
setState(() {
});
},
);
},
),
),
),
],
),
Custom Dropdown for Age
class CustomAgeDropDown extends StatefulWidget {
final String ageValue;
final InputDecoration decoration;
final Function onChanged;
CustomAgeDropDown(
{this.ageValue, this.decoration, this.onChanged});
@override
_CustomAgeDropDownState createState() => _CustomAgeDropDownState();
}
class _CustomAgeDropDownState extends State<CustomAgeDropDown> {
List<String> adultAgeList = List<String>.generate(100, (int index) => '${index+1 * 18}');
@override
Widget build(BuildContext context) {
List<DropdownMenuItem> adult = adultAgeList.map((val) => DropdownMenuItem(value: val, child: Text(val,style: GoogleFonts.poppins(),))).toList();
return DropdownButtonFormField(
onChanged: widget.onChanged,
decoration: widget.decoration,
isDense: true,
value: widget.ageValue,
items: adult,
);
}
}
After make check list-tile count dropdown will visible then I choose no son count after choosing no of son count then no of selected count dropdown created. I just want to get value from each dropdown.
from How can get value from each dropdown?
No comments:
Post a Comment