title: How to generate list of items from checkbox selection in flutter?
body: <p>I am trying to create a list of ids &amp; names from checkbox selection and i want to pass that array list in navigator.pop but somehow i am not able to do it.?</p>
  
  <p>I tried to create model and put that as in list object which can give me my selected values in list or array but I am getting it with last extra (comma(,))</p>
  
  <p>My checkbox and code to create list and pass it into navigator.pop.</p>
  
  <pre><code>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) =&gt; RoomFacilities()));
          for (int i = 0; i &lt; 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&lt;RoomFacilityModel.Message&gt; tempRoomData =
        List&lt;RoomFacilityModel.Message&gt;();
    //
    List&lt;RoomFacilityModel.Message&gt; roomListOBJ =
        List&lt;RoomFacilityModel.Message&gt;();
  
  onPressed: () {
                    Navigator.pop(context, tempRoomData);
                    for (int i = 0; i &lt; tempRoomData.length; i++) {
                      print(
                          "City List : ${tempRoomData[i].fcid} + ${tempRoomData[i].name} ");
                    }
                  },
  
  -------------------   Code for checkbox  ------------------
  
  Container(
                  child: CheckboxListTile(
                      title: Row(
                        children: &lt;Widget&gt;[
                          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]
  </code></pre>