hanshengchiu / reorderables

Reorderable table, row, column, wrap, and sliver list that allow drag and drop of the children. https://pub.dartlang.org/packages/reorderables
MIT License
729 stars 168 forks source link

Can't use Flexible inside ReorderableRow #113

Closed bdlukaa closed 3 years ago

bdlukaa commented 3 years ago

I'm trying to use a Flexible inside ReorderableRow, but it says it has the wrong ancestor: a Semantics widget.

I took a look at the code and it seems you're wrapping each child in a Semantics widget, impossibiliting the use of Flexibles and Expandeds:

      return MergeSemantics(
        child: Semantics(
          customSemanticsActions: semanticsActions,
          child: toWrap,
        ),
      );
Full log The following assertion was thrown while applying parent data.: Incorrect use of ParentDataWidget. The ParentDataWidget Flexible-[](flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type ParentData. Usually, this means that the Flexible widget has the wrong ancestor RenderObjectWidget. Typically, Flexible widgets are placed directly inside Flex widgets. The offending Flexible is currently placed inside a Semantics widget. The ownership chain for the RenderObject that received the incompatible parent data was: Semantics ← _FocusMarker ← Focus ← HoverButton ← _Tab ← Flexible-[] ← Semantics ← MergeSemantics ← MetaData ← Listener ← ⋯ When the exception was thrown, this was the stack: #0 RenderObjectElement._updateParentData. (package:flutter/src/widgets/framework.dart:5626:11) #1 RenderObjectElement._updateParentData (package:flutter/src/widgets/framework.dart:5642:6) #2 RenderObjectElement.attachRenderObject (package:flutter/src/widgets/framework.dart:5664:7) #3 RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5357:5) #4 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5973:11) ... Normal element mounting (72 frames) #76 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14) #77 Element.updateChild (package:flutter/src/widgets/framework.dart:3306:18) #78 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5561:32) #79 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6105:17) #80 Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15) #81 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16) #82 Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5) #83 StatelessElement.update (package:flutter/src/widgets/framework.dart:4576:5) #84 Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
diegotori commented 3 years ago

Looks like ReorderableFlex, which is ReorderableRow's parent, doesn't extend Flex. Rather, it re-implements that class so that it works in a reorderable fashion. As a workaround, you could wrap your Flexible with either a Row or Column, which does extend Flex:

ReorderableRow(
  children: [
    Row(
      children: [
         Flexible(...)
      ]
    )
  ]
)
bdlukaa commented 3 years ago

Thanks for this workaround 🤗