【发布时间】:2019-04-19 13:08:43
【问题描述】:
我正在尝试从复选框选择中创建一个 id 和名称列表,我想在 navigator.pop 中传递该数组列表,但不知何故我无法做到。?
我尝试创建模型并将其放在列表对象中,它可以在列表或数组中为我提供我选择的值,但我得到了最后一个额外的(逗号(,))
我的复选框和代码用于创建列表并将其传递给 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]
【问题讨论】:
标签: android dart flutter checkboxlist