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

Viewed 31

Please please help me .. I found this code from a software site, but only used list of string but I have List tasks; so I can't view the data of List tasks; In the Recordable list view and also the value of the key in the Recordable list view I didn't understand it..Does anyone have an idea to solve this?

     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);
                });
              }),
        );
      }
    }
1 Answers

I found this code from a software site

If you're new to Flutter and programming in general, while it's good to read code, it might be not a good idea to just copy and paste code. It would be good to actually understand it and also to understand the programming language you're using. I suggest reading this.

but only used list of string but I have List tasks

You didn't provide what your "Task" class is, so I can just help you with some pseudocode. In your ReordableListView's itemBuilder function you have to extract your data, somehow:

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

Unluckily without further info this is the best I can do

Related