[英]Flutter and Dart - how can I copy only a Item from a list and add this Item to another list?
Hi I am trying to copy only one item from a list into another list.嗨,我试图仅将列表中的一项复制到另一个列表中。
Example 1: listFinalDevices = listDevices.map((index) => index).toList();
示例 1: listFinalDevices = listDevices.map((index) => index).toList();
works a bit, but this overwrites the listFinalDevice every time, I need to add the selected Item from the listDevice.有点工作,但这每次都会覆盖listFinalDevice,我需要从listDevice中添加选定的项目。 As a kind of favorite device list.作为一种喜欢的设备列表。
Example 2: listFinalDevices.insertAll(listFinalDevices.length,listDevices.map((index) => index).toList());
示例 2: listFinalDevices.insertAll(listFinalDevices.length,listDevices.map((index) => index).toList());
This copy the complete list but I need only the over index referenced item.这复制了完整的列表,但我只需要过度索引引用的项目。
Can someone give me a link to an example or what are the keywords for what I have to search.有人可以给我一个示例的链接,或者我必须搜索的关键字是什么。
UPDADTE: To make it more clearer, currently I have the following data in the list named listDevices:更新:为了更清楚,目前我在名为 listDevices 的列表中有以下数据:
[ScanResult{device: BluetoothDevice{id: 4D:55:F7:CE:03:FA, name: , type: BluetoothDeviceType.unknown, isDiscoveringServices: false, _services: [], advertisementData: AdvertisementData{localName: , txPowerLevel: null, connectable: true, manufacturerData: {}, serviceData: {0000fd6f-0000-1000-8000-00805f9b34fb: [215, 226, 39, 186, 231, 145, 9, 162, 217, 184, 33, 163, 133, 92, 23, 221, 40, 117, 217, 176]}, serviceUuids: [0000fd6f-0000-1000-8000-00805f9b34fb]}, rssi: -65}, ScanResult{device: BluetoothDevice{id: 00:80:E1:21:C4:B5, name: P2PSRV1, type: BluetoothDeviceType.le, isDiscoveringServices: false, _services: [], advertisementData: AdvertisementData{localName: P2PSRV1, txPowerLevel: null, connectable: true, manufacturerData: {33537: [0, 0, 32, 0, 0, 128, 225, 33, 196, 181]}, serviceData: {}, serviceUuids: []}, rssi: -35}, ScanResult{device: BluetoothDevice{id: 60:29:4D:9B:AC:52, name: , type: BluetoothDeviceType.unknown, isDiscoveringServices: false, _services: [], advertisementData: Adver
The target is, that I chose some Devices and put this to a kind of favorite list which should named with listFinalDevices:目标是,我选择了一些设备并将其放入一种应以 listFinalDevices 命名的收藏夹列表中:
[ScanResult{device: BluetoothDevice{id: 00:80:E1:21:C4:B5, name: P2PSRV1, type: BluetoothDeviceType.le, isDiscoveringServices: false, _services: [], advertisementData: AdvertisementData{localName: P2PSRV1, txPowerLevel: null, connectable: true, manufacturerData: {33537: [0, 0, 32, 0, 0, 128, 225, 33, 196, 181]}, serviceData: {}, serviceUuids: []}, rssi: -35}, ScanResult{device: BluetoothDevice{id: C5:9F:97:96:4A:A9, name: MX Anywhere 2S, type: BluetoothDeviceType.le, isDiscoveringServices: false, _services: [], advertisementData: AdvertisementData{localName: MX Anywhere 2S, txPowerLevel: 4, connectable: false, manufacturerData: {}, serviceData: {}, serviceUuids: [00001812-0000-1000-8000-00805f9b34fb]}, rssi: -50}] is not empty
listFinalDevices.add(listDevices[index])
Could you be clearer?你能说清楚点吗? You wanted to add object at index from another list to final list, right?您想将另一个列表中的索引处的对象添加到最终列表中,对吗?
or maybe:或者可能:
listFinalDevices.add(listDevices[listDevices.indexWhere((el) => el == index)])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.