簡體   English   中英

如何從 map 列表中獲取數據以顯示在可記錄列表視圖中

[英]How to get data from list of map to display in Recordable list view

請幫幫我..我從軟件站點找到了這段代碼,但只使用了字符串列表,但我有列表任務; 所以無法查看List任務的數據; 在可記錄列表視圖中以及可記錄列表視圖中鍵的值我不明白..有人有解決這個問題的想法嗎?

     final List<String> _products =
      List.generate(100, (index) => "Product ${index.toString()}");
Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: const Text('Kindacode.com'),
          ),
          body: ReorderableListView.builder(
              itemCount: _products.length,
              itemBuilder: (context, index) {
                final String productName = _products[index];
                return Card(
                  key: ValueKey(productName),
                  color: Colors.amberAccent,
                  elevation: 1,
                  margin: const EdgeInsets.all(10),
                  child: ListTile(
                    contentPadding: const EdgeInsets.all(25),
                    title: Text(
                      productName,
                      style: const TextStyle(fontSize: 18),
                    ),
                    trailing: const Icon(Icons.drag_handle),
                    onTap: () {/* Do something else */},
                  ),
                );
              },
              // The reorder function
              onReorder: (oldIndex, newIndex) {
                setState(() {
                  if (newIndex > oldIndex) {
                    newIndex = newIndex - 1;
                  }
                  final element = _products.removeAt(oldIndex);
                  _products.insert(newIndex, element);
                });
              }),
        );
      }
    }

我從一個軟件站點找到了這段代碼

如果您是 Flutter 和一般編程新手,雖然閱讀代碼很好,但僅復制和粘貼代碼可能不是一個好主意。 真正理解它並理解您正在使用的編程語言會很好。 我建議閱讀這個

但只使用了字符串列表,但我有列表任務

您沒有提供您的“任務” class 是什么,所以我可以幫助您提供一些偽代碼。 在您的ReordableListViewitemBuilder function 中,您必須以某種方式提取數據:

final yourTask = _products[index];
final yourTaskName = yourTask.name;  // example

不幸的是,沒有更多信息,這是我能做的最好的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM