How to use Wrapper classes (with Lists)?

Viewed 36

I use ReorderableListView in one of my projects. It offers this wrapper class that takes a child and wraps it so that it can now be selected for dragging. I tried to use that to make my entire ListTiles draggable. I dont know the "common convention" or easiest way to implement that. This is my try:

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("your affirmations"),
      ),
      body: ReorderableListView(
        onReorder: onReorder,
        children: getListItems(),
      ),
    );
  }

  List<ReorderableDragStartListener> getListItems() => yourAffirmations
      .asMap()
      .map((index, item) => MapEntry(
          index,
          ReorderableDragStartListener(
              index: index, child: buildAffirmationListTile(item, index))))
      .values
      .toList();

  ListTile buildAffirmationListTile(String item, int index) => ListTile(
        key: ValueKey(item),
        title: Text(item),
        leading: Text("${index + 1}"),
      );

_AssertionError ('package:flutter/src/material/reorderable_list.dart': Failed assertion: line 96 pos 10: 'children.every((Widget w) => w.key != null)': All children of this widget must have a key.)

But this leaves me with an error I get while compiling which I don't understand

_AssertionError ('package:flutter/src/material/reorderable_list.dart': Failed assertion: line 96 pos 10: 'children.every((Widget w) => w.key != null)': All children of this widget must have a key.)

1 Answers

I figured it out. Simply wrap the widget with another one using "ctrl+."

Related