flutter 无法在包含两个 listview 的屏幕中使用 reordableListView

moh*_*ani 3 listview dart flutter

这是我的代码,我有一行包含两个堆栈,每个堆栈都有一个列表视图,左侧小部件有一个包含 reordablelistView 的堆栈,但是当拖动其中的元素时会出现此错误

Scaffold(
    body: Container(
      width: width,
      child: Row(
        children: <Widget>[
          RightWidget(),// a listview
          Container(
            width: 1.5,
            color: Colors.grey,
          ),
          LeftWidget()
        ],
      ),
    ),)
Run Code Online (Sandbox Code Playgroud)

我的 reordablelistview 是

class _RightWidgetState extends State<RightWidget> {
@override
Widget build(BuildContext context) {
print('right widget called');
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Stack(
  children: <Widget>[


    Container(
      color: Color(0xFF1B1D22),
      width: (1 / 4) * width + 10,
      child://new reordable list added



       ReorderableListView(

                  children:
                List.generate(Provider.of<ClassroomBlac>(context).classes[Provider.of<ClassroomBlac>                      (context).numberclass].moves.length, (index) {
                  return _itemBuilder(context,index);
                }), onReorder: (int oldIndex, int newIndex) {

                Provider.of<ClassroomBlac>(context).changeMoveIndex(newIndex, oldIndex);

                })
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

I/flutter (25693): Another exception was thrown: A RenderFlex overflowed by 2.0 pixels on the bottom.
I/flutter (25693): Another exception was thrown: A RenderFlex overflowed by 2.0 pixels on the bottom.
I/flutter (25693): Another exception was thrown: A RenderFlex overflowed by 11 pixels on the right.
I/flutter (25693): Another exception was thrown: ScrollController attached to multiple scroll views.
Run Code Online (Sandbox Code Playgroud)

我在列表中使用它的小部件是

Widget _itemBuilder(BuildContext context, int count) {
 print('video thumbnail build in listview');
 return GestureDetector(
  key: UniqueKey(),//new
   onTap: () {
    // Provider.of<ClassroomBlac>(context).setOptionView(context);//set options for view
    //ToDo:if name dont update must refresh moves of class lenght
    Provider.of<ClassroomBlac>(context,listen: false).setMoveIndex(count);
    Provider.of<CheckOneRunVideo>(context,listen: false).setIndex(count);

    if (Provider.of<ButtonAddStateBloc>(context).editingState)
      Provider.of<ClassroomBlac>(context)
          .classes[Provider.of<ClassroomBlac>(context).numberclass]
          .moves[count]
          .isselectedfor =
      !Provider.of<ClassroomBlac>(context)
          .classes[Provider.of<ClassroomBlac>(context).numberclass]
          .moves[count]
          .isselectedfor;
  },
  child: Container(
    margin: EdgeInsets.only(bottom: 8),
    child: VideoThumbnailItem(count),
  ));
 }
Run Code Online (Sandbox Code Playgroud)

如果我使用控制器,请帮助我,如果是的话,如果我正确生成列表项如何?什么是不正确的?

当我评论包含列表视图的 leftWidget() 时,我的代码工作正常

Joe*_*ler 5

不确定当您遇到此问题时是否存在此问题,但 ReorderableListView现在有一个 scrollController 属性。

所以声明你的scrollController是这样的:

final ScrollController reorderScrollController = ScrollController();
Run Code Online (Sandbox Code Playgroud)

然后将该唯一的scrollController分配给您的ReorderableListView:

ReorderableListView(
   scrollController: reorderScrollController,
   ...
)
Run Code Online (Sandbox Code Playgroud)