簡體   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