I have a listview builder and have a dropdown in each element it's in an expansion tile widget and under expansion tile have a dropdown as I said now if I select dropdown value then a listview builder creates that number of the list if I click on that list element its shows a dialog has a dropdown if the select value on that it reflects on first listview builder 2nd element generated list by dropdown in first element dropdown.
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class dynamicList2 extends StatefulWidget {
@override
_dynamicList2State createState() => _dynamicList2State();
}
class _dynamicList2State extends State<dynamicList2> {
List roomAvailable = [];
List adultList = [];
List<String> selectedItemValue = List<String>();
List<String> selectAdults = List<String>();
List<TextEditingController> priceController = [];
Map<dynamic, dynamic> hello = {
"room_list": [
{
"roomtype": "bedroom",
"room_id": "1",
"available": [
{"value": 1, "no_room": 1},
{"value": 2, "no_room": 2},
{"value": 3, "no_room": 3},
{"value": 4, "no_room": 4}
],
"adultList": [
{"value": 1, "adult": 1},
{"value": 2, "adult": 2},
{"value": 3, "adult": 3},
{"value": 4, "adult": 4}
]
},
{
"roomtype": "premium delux room",
"room_id": "2",
"available": [
{"value": 1, "no_room": 1},
{"value": 2, "no_room": 2},
{"value": 3, "no_room": 3},
{"value": 4, "no_room": 4},
{"value": 5, "no_room": 5}
],
"adultList": [
{"value": 1, "adult": 1},
{"value": 2, "adult": 2},
{"value": 3, "adult": 3}
]
},
{
"roomtype": "myroomType",
"room_id": "3",
"available": [
{"value": 1, "no_room": 1},
{"value": 2, "no_room": 2},
],
"adultList": [
{"value": 1, "adult": 1},
{"value": 2, "adult": 2},
{"value": 3, "adult": 3},
{"value": 3, "adult": 4},
{"value": 3, "adult": 5}
]
}
]
};
Widget reservationBox() {
return ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: hello["room_list"].length,
itemBuilder: ((context, index) {
roomAvailable = hello["room_list"][index]["available"];
// print(roomAvailable);
adultList = hello["room_list"][index]["adultList"];
print(adultList);
selectAdults.add("1");
priceController.add(new TextEditingController());
selectedItemValue.add("1");
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Column(
children: [
Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.white),
child: ListTileTheme(
dense: true,
child: ExpansionTile(
trailing: Icon(Icons.keyboard_arrow_down,
color: Color.fromRGBO(255, 109, 112, 1.0)),
backgroundColor: Colors.white,
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(hello["room_list"][index]["roomtype"],
style: GoogleFonts.montserrat(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Color.fromRGBO(255, 109, 112, 1.0))),
Text(
hello["room_list"][index]["available"]
.length
.toString(),
style: GoogleFonts.montserrat(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Color.fromRGBO(255, 109, 112, 1.0)),
),
],
),
children: <Widget>[
Divider(
thickness: 1.0,
height: 1.0,
),
SizedBox(
height: 10,
),
expansionData2(
index, hello["room_list"][index]["roomtype"])
/*expansionData()*/
],
),
),
),
SizedBox(
height: 16,
),
],
),
);
}),
);
}
Widget expansionData2(index, String val) {
// print(index);
return Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0, vertical: 6.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Add Rooms",
style: GoogleFonts.montserrat(
fontSize: 15.5,
fontWeight: FontWeight.w500,
color: Color.fromRGBO(2, 15, 67, 1))),
Container(
width: 90,
child: DropdownButtonFormField(
decoration: InputDecoration(border: InputBorder.none),
value: selectedItemValue[index].toString(),
items: roomAvailable.map((item) {
return DropdownMenuItem(
child: Text(
item['no_room'].toString(),
style: GoogleFonts.montserrat(
fontSize: 18,
fontWeight: FontWeight.w300,
color: Colors.black54),
),
value: item['value'].toString(),
);
}).toList(),
onChanged: (value) {
setState(() {
selectedItemValue[index] = value;
print(selectedItemValue[index].toString());
print(selectedItemValue);
});
},
hint: Text(
'Select',
style: TextStyle(
color: Colors.grey,
fontSize: 16,
fontWeight: FontWeight.w500),
),
),
),
],
),
),
dynamicBox3(index, val),
],
);
}
Widget dynamicBox3(hello, String val) {
return Container(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: int.parse(selectedItemValue[hello]),
itemBuilder: (context, myindex) {
myindex = myindex + 1;
return Column(
children: [
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 15.0, vertical: 5),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Room $myindex",
style: GoogleFonts.montserrat(
fontSize: 13.5,
fontWeight: FontWeight.w500,
color: Color.fromRGBO(2, 15, 67, 1))),
InkWell(
child: Icon(
Icons.keyboard_arrow_right,
size: 22,
color: Color.fromRGBO(2, 15, 67, 1),
),
onTap: () {
dialogBox(myindex, val);
},
),
],
),
),
],
);
}),
);
}
void dialogBox(myindex, val) {
showDialog(
child: SingleChildScrollView(
child: Dialog(
insetPadding: EdgeInsets.all(16.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15.0))),
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Padding(
padding: const EdgeInsets.all(18.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Room -$myindex :',
style: GoogleFonts.montserrat(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Color.fromRGBO(255, 109, 112, 1.0)),
),
IconButton(
icon: Icon(
Icons.close,
size: 30,
),
onPressed: () {
Navigator.pop(context);
},
),
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Adults :',
style: GoogleFonts.montserrat(
fontSize: 17,
fontWeight: FontWeight.w500,
color: Color.fromRGBO(2, 15, 67, 1)),
),
Container(
width: MediaQuery.of(context).size.width / 2.5,
height: 40,
decoration: BoxDecoration(
border: Border.all(color: Colors.grey, width: 1),
borderRadius: BorderRadius.circular(8)),
child: Padding(
padding: const EdgeInsets.only(
left: 10, right: 3, bottom: 6),
child: DropdownButtonFormField(
decoration: InputDecoration(
border: InputBorder.none,
contentPadding:
const EdgeInsets.only(bottom: 6.0),
),
value: selectAdults[myindex].toString(),
items: adultList.map((item) {
return DropdownMenuItem(
child: Text(
item['adult'].toString(),
style: GoogleFonts.montserrat(
fontSize: 18,
fontWeight: FontWeight.w300,
color: Colors.black54),
),
value: item['value'].toString(),
);
}).toList(),
onChanged: (value) {
selectAdults[myindex] = value;
print(selectAdults[myindex]);
},
hint: Text(
'Select',
style: TextStyle(
color: Colors.grey,
fontSize: 16,
fontWeight: FontWeight.w500),
),
),
),
),
],
),
Align(
alignment: Alignment.center,
child: RaisedButton(
child: Text(
'Save',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w500),
),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
color: Colors.green,
onPressed: () {
Navigator.pop(context);
},
),
),
],
),
),
),
),
),
context: context,
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("ListView2"),
),
body: SingleChildScrollView(
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 20.0, horizontal: 26),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 28),
child: Divider(
thickness: 1.0,
height: 1.0,
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Color.fromRGBO(255, 109, 112, 1.0),
),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 10.0, horizontal: 8),
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 13.0, vertical: 20),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text('Room Type',
style: GoogleFonts.montserrat(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.white)),
Text('Available',
style: GoogleFonts.montserrat(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.white)),
Text('Details',
style: GoogleFonts.montserrat(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.white)),
],
),
),
reservationBox(),
],
),
),
),
],
),
),
],
),
),
),
),
);
}
}