我正在尝试从复选框选择中创建ID和名称的列表,我想在navigator.pop中传递该数组列表,但是以某种方式我无法做到这一点。?
我试图创建模型并将其放在列表对象中,这样可以给我选定的值在列表或数组中,但是我在最后一个(comma(,))上得到了它
我的复选框和代码以创建列表并将其传递到navigator.pop。
THIS IS MAIN PAGE WHERE I WANT TO GET AND REDIRECT TO SECOND LIST PAGE.
var tempRoomFace;
getRoomFaceData() async {
tempRoomFace = await Navigator.push(
context, MaterialPageRoute(builder: (context) => RoomFacilities()));
for (int i = 0; i < areaDataResult.length; i++) {
_selectedroom = _selectedroom + tempRoomFace[i].name + ", ";
_selectedroomID = _selectedroomID + tempRoomFace[i].id + ", ";
print("selected rooms : $_selectedroomID");
}
}
THIS IS LIST PAGE... TO CREATE LIST
------------------ code for passing value ---------------------
List<RoomFacilityModel.Message> tempRoomData =
List<RoomFacilityModel.Message>();
//
List<RoomFacilityModel.Message> roomListOBJ =
List<RoomFacilityModel.Message>();
onPressed: () {
Navigator.pop(context, tempRoomData);
for (int i = 0; i < tempRoomData.length; i++) {
print(
"City List : ${tempRoomData[i].fcid} + ${tempRoomData[i].name} ");
}
},
------------------- Code for checkbox ------------------
Container(
child: CheckboxListTile(
title: Row(
children: <Widget>[
Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: Colors.black,
),
height: 26,
width: 26,
child: Image.network(
roomListOBJ[index].icon,
),
),
SizedBox(width: 10),
Text(roomListOBJ[index].name),
],
),
value: roomListOBJ[index].isCheck,
onChanged: (bool value) async {
//
setState(() {
roomListOBJ[index].isCheck = value;
if (value) {
tempRoomData.add(RoomFacilityModel.Message(
fcid: roomListOBJ[index].fcid,
name: roomListOBJ[index].name));
} else {
tempRoomData.removeAt(index);
}
});
}),
);
I want to get resulat on my main page as
tempRoomFace = [TV, Safe box, curtains, iron]
tempRoomFaceID = [3,4,8,1]
答案 0 :(得分:0)
您可以根据需要进行任意修改。
BDF → C