If a ReorderableListView is nested inside another Scrollable Widget, it doesn't Reorder Scroll to the top

272 Views Asked by At

ReorderableListView is nested inside another Scrollable Widget, it doesn't Reorder Scroll to the top. Any help would be most welcome, thank you!.

Here is issue video link https://drive.google.com/file/d/1Ct3jhA-JNW1kLX_dW1VPwXvFS-IwW77L/view?usp=sharing

Here is my code :

  List<String> _list = ["Apple", "Ball", "Cat", "Dog", "Elephant","Apple1","Apple2","Apple3",];

@override
  Widget build(BuildContext context) {
    final signInProvider = Provider.of<SignInController>(context);
    return Scaffold(
      backgroundColor: Colors.white,
      body: SafeArea(
          child: Center(
        child: Padding(
          padding: const EdgeInsets.all(25.0),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              SizedBox(height: 4),
              FlutterLogo(size: 200),
              Expanded(
                child: ListView(
                  shrinkWrap: true,
                  children: [
                    const SizedBox(height: 30),
                    Text("Any Text here"),
                    const SizedBox(height: 40),
                    ReorderableListView(
                      shrinkWrap: true,
                      dragStartBehavior : DragStartBehavior.start,
                      physics: ClampingScrollPhysics(),
                      children: _list.map((item) => ListTile(key: Key("${item}"), title: Text("${item}"), trailing: Icon(Icons.menu),)).toList(),
                      onReorder: (int start, int current) {
                        // dragging from top to bottom
                        if (start < current) {
                          int end = current - 1;
                          String startItem = _list[start];
                          int i = 0;
                          int local = start;
                          do {
                            _list[local] = _list[++local];
                            i++;
                          } while (i < end - start);
                          _list[end] = startItem;
                        }
                        // dragging from bottom to top
                        else if (start > current) {
                          String startItem = _list[start];
                          for (int i = start; i > current; i--) {
                            _list[i] = _list[i - 1];
                          }
                          _list[current] = startItem;
                        }
                        setState(() {});
                      },
                    ),
                    const SizedBox(height: 30),
                    Text("Any Text here"),
                    const SizedBox(height: 30),
                  ],
                ),
              )
            ],
          ),
        ),
      )),
    );
  }
1

There are 1 best solutions below

1
On

Try this :

  List<String> _list = ["Apple", "Ball", "Cat", "Dog", "Elephant","Apple1","Apple2","Apple3",];

@override
  Widget build(BuildContext context) {
    final signInProvider = Provider.of<SignInController>(context);
    return Scaffold(
      backgroundColor: Colors.white,
      body: SafeArea(
          child: Center(
        child: Padding(
          padding: const EdgeInsets.all(25.0),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              SizedBox(height: 4),
              FlutterLogo(size: 200),
              Expanded(
                child: ListView(
                  shrinkWrap: true,
                  children: [
                    const SizedBox(height: 30),
                    Text("Any Text here"),
                    const SizedBox(height: 40),
                    ReorderableListView(
                      shrinkWrap: true,
                      dragStartBehavior : DragStartBehavior.start,
                      physics: NeverScrollablePhysics(),
                      children: _list.map((item) => ListTile(key: Key("${item}"), title: Text("${item}"), trailing: Icon(Icons.menu),)).toList(),
                      onReorder: (int start, int current) {
                        // dragging from top to bottom
                        if (start < current) {
                          int end = current - 1;
                          String startItem = _list[start];
                          int i = 0;
                          int local = start;
                          do {
                            _list[local] = _list[++local];
                            i++;
                          } while (i < end - start);
                          _list[end] = startItem;
                        }
                        // dragging from bottom to top
                        else if (start > current) {
                          String startItem = _list[start];
                          for (int i = start; i > current; i--) {
                            _list[i] = _list[i - 1];
                          }
                          _list[current] = startItem;
                        }
                        setState(() {});
                      },
                    ),
                    const SizedBox(height: 30),
                    Text("Any Text here"),
                    const SizedBox(height: 30),
                  ],
                ),
              )
            ],
          ),
        ),
      )),
    );
  }