繁体   English   中英

Flutter 和 Dart - 如何仅从列表中复制一个项目并将此项目添加到另一个列表中?

[英]Flutter and Dart - how can I copy only a Item from a list and add this Item to another list?

嗨,我试图仅将列表中的一项复制到另一个列表中。

示例 1: listFinalDevices = listDevices.map((index) => index).toList(); 有点工作,但这每次都会覆盖listFinalDevice,我需要从listDevice中添加选定的项目。 作为一种喜欢的设备列表。

示例 2: listFinalDevices.insertAll(listFinalDevices.length,listDevices.map((index) => index).toList()); 这复制了完整的列表,但我只需要过度索引引用的项目。

有人可以给我一个示例的链接,或者我必须搜索的关键字是什么。

更新:为了更清楚,目前我在名为 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

目标是,我选择了一些设备并将其放入一种应以 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])

你能说清楚点吗? 您想将另一个列表中的索引处的对象添加到最终列表中,对吗?

或者可能:

listFinalDevices.add(listDevices[listDevices.indexWhere((el) => el == index)])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM