fluttergogo
fluttergogo

Reputation: 113

Flutter: ReorderableListViewChildGlobalKey used by Multiple widgets error

Error I get is: The key [_ReorderableListViewChildGlobalKey ValueKey#46dc3] was used by multiple widgets

Each item in my list is already uniquely identified in my dismissable widget.

Widget mainCardWidget(BuildContext context) {
    return ReorderableListView(
      onReorder: onReorder,
      physics: const BouncingScrollPhysics(
          parent: AlwaysScrollableScrollPhysics()),
      children: _getListItems(),
    );
  }

  void onReorder(int oldIndex, int newIndex) {
    setState(() {
      if (newIndex > oldIndex) {
        newIndex -= 1;
      }
      final Rung element = _items.removeAt(oldIndex);
      _items.insert(newIndex, element);
    });
  }

  List<Widget> _getListItems() => _items
      .asMap()
      .map((i, item) => MapEntry(i, _buildTenableListTile(item, i)))
      .values
      .toList();

  Widget _buildTenableListTile(Rung item, int index) {
    return Dismissible(
      key: Key(item.rungId),
      onDismissed: (direction) {
        setState(() {
          _items.removeAt(index);
          _removeditems.add(item);
        });
      },
      background: Container(color: Colors.red),
      child: Padding(
        padding: const EdgeInsets.all(20.0),
        child: Card(child: cardWithInfoPage(item, context, index)),
      ),
    );
  }

Upvotes: 0

Views: 36

Answers (1)

fluttergogo
fluttergogo

Reputation: 113

I replaced the key with key: UniqueKey() to my Dismissible widget and that solved this problem.

Upvotes: 1

Related Questions