简体   繁体   English

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

[英]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.

相关问题 如何转换列表<Item>到地图<Datetime, List<Item> &gt; 在飞镖/颤振中 - How can I convert List<Item> to Map<Datetime, List<Item>> in dart / Flutter 如何将一个列表中的项目添加到另一个列表 - How to add an item from a list to another list 如何 select 列表中的特定项目 Flutter/Dart - how to select a specific item from a list Flutter/Dart 如何修改Flutter中地图列表中的项目| Dart - How to modify a item from List of Maps in Flutter | Dart 如果列表中的项目在另一个列表中,我如何签入 Pandas? - How can I check in Pandas if an item from a list is in an another list? 如何将新项目添加到 map 列表以及如何删除 Flutter 中的项目 - How can I add a new item to a list of map and how to remove a item in Flutter 如何在List中的另一个项目之后添加项目? - How to add an item after another item in List? Flutter 将项目添加到列表 - Flutter add item to list 使用 Dart 和 Flutter,如何将动态小部件中的数据保存到另一个列表内的地图列表中 - Using Dart and Flutter, how can I save data from a dynamic widget, into a list of maps, that is inside of another list 如何将列表中的每个项目添加到另一个列表中的字典? - How to add each item from a list to dictionaries from another list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM