I am trying to make a ReorderableListView, which needs a key. I put it, however it returns the error "All children of this widget must have a key". Can anyone help me? (I've seen similar problems here but I still couldn't solve it). I saw some examples that used the key of this form, however the index it does not recognize the index as shown in the image

ReorderableListView(
              onReorder: _onReorder,
              scrollDirection: Axis.vertical,
              padding: const EdgeInsets.symmetric(vertical: 8),
              children: <Widget>[
                ListView.builder(
                    itemCount: dias.length,
                    itemBuilder: (context, int index) {
                      return Padding(
                        key: ValueKey(dias[index]),
                        padding: EdgeInsets.all(0),
                        child: _cartaodia(context, index),
                      );
                    }
                ),
          ],
          )

enter image description here


Solution 1: Ajay Kumar

Reason: As you are passing a ListView as a child to ReorderableListView.

Try something like this

    class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  List<int> _dataList = List.generate(10, (_) => _);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Expanded(
          child: ReorderableListView(
            onReorder: (X, Y) {},
            scrollDirection: Axis.vertical,
            padding: const EdgeInsets.symmetric(vertical: 8),
            children: _dataList
                .map((data) => Padding(
                      key: Key('$data'),
                      padding: EdgeInsets.all(0),
                      child: Text(
                        '$data',
                        style: TextStyle(color: Colors.grey),
                      ),
                    ))
                .toList(),
          ),
        )
      ],
    );
  }
}