'How to create different keys for ReordableListView, in async enviroment?

I am trying to create fake firebase, and i have problem with "key: ValueKey(index),". I am trying create elements in "ReorderableListView".

FutureBuilder<List<FirstListModel>>(
                  future: fakeFirebase.getList(),
                  builder: (context, snapshot) {
                    return snapshot.data != null
                        ? ReorderableListView.builder(
                            (some code)
                            itemCount: snapshot.data!.length,
                            itemBuilder: (context, index) {
                              if (snapshot.data != null) {
                                for (var item in snapshot.data!) {
                                  return buildPlate(index, item);
                                }
                              } else {
                                return const CircularProgressIndicator();
                              }
                              throw Exception("Error I am Empty");
                            },
                          )
                        : const CircularProgressIndicator();
                  },
                )

i am creating items for that ReorderableListView in floatingActionButton which is in my Scaffold:

Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: _addWidget,
      ),
      (some code)
      body: Center(
          child: fakeFirebase.firstList.isNotEmpty
              ? FutureBuilder<List<FirstListModel>>(

this code is in my floatingActionButton:

void _addWidget() {
    lol++;
    final item = FirstListModel(text: lol.toString(), id: lol.toString());
    setState(() {
      fakeFirebase.addElement(item);
    });
  }

this place is my "key", which is creating my problems:

  Widget buildPlate(int index, FirstListModel oneElement) {
    return ListTile(
      key: ValueKey(index),

this is my model:

class FirstListModel {
  String text;
  String id;
  FirstListModel({
    required this.text,
    required this.id,
  });
}

right now i put in my "key" index, in hope it will not create an error, sadly when i press my floatingActionButton in order to add new elements it only shows meany times one element. I want to create new elements that cen be edited and deleted, drag and droped, but i know this "key" is a reson that i am not able to do it, someon have a solution to my problem? if you need more code, i can provide it, i am creating this app to learn.

enter image description here



Solution 1:[1]

if someon find this problem, i found a solution:

i had problem in here:

 itemBuilder: (context, index) {
                              if (snapshot.data != null) {
                                for (var item in snapshot.data!) {
                                  return buildPlate(index, item);
                                }
                              } 

i needed to change this as follows:

itemBuilder: (context, index) {
                              if (snapshot.data?[index] != null) {
                                return buildPlate(index, snapshot.data![index]);
                              } else {
                                return const CircularProgressIndicator();
                              }
                              throw Exception("Error I am Empty");
                            },

now I have still a problems, but it is running

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1