Skip to content

Reversed ReorderableListView drop animation moves item one row higher than it should #110949

Closed

Description

@JanPolasek

Steps to Reproduce

  1. Create a reversed ReorderableListView. It can be reproduced very easily in the ReorderableListView demo in Flutter docs by adding the reverse: true argument.
  1. Try reordering the items and observe the drop animation

Just a sidenote: this issue may be related to #90856, but the circumstances are a little different.

Expected result:
The reorder drop animation should end where the item is supposed to go, just like when using a non-reversed ReorderableListView.
I am a little bad at explaining so here's a video of the correct behaviour:

Screenshot.2022-09-04.at.20.32.09.mp4

Actual result:
The item "gravitates" one row higher than it should before jumping to its right position. It only works correctly when swapping places with an item that's directly next to the one that's being moved.

Screenshot.2022-09-04.at.20.20.56.mp4
Code sample It can be reproduced in the example in the docs, but in case the page changes I'll copy it here
import 'package:flutter/material.dart';

void main() => runApp(const ReorderableApp());

class ReorderableApp extends StatelessWidget {
  const ReorderableApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('ReorderableListView Sample')),
        body: const ReorderableExample(),
      ),
    );
  }
}

class ReorderableExample extends StatefulWidget {
  const ReorderableExample({super.key});

  @override
  State<ReorderableExample> createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<ReorderableExample> {
  final List<int> _items = List<int>.generate(50, (int index) => index);

  @override
  Widget build(BuildContext context) {
    final ColorScheme colorScheme = Theme.of(context).colorScheme;
    final Color itemColor = colorScheme.primary.withOpacity(0.05);

    return ReorderableListView(
      reverse: true,
      padding: const EdgeInsets.symmetric(horizontal: 40),
      children: <Widget>[
        for (int index = 0; index < _items.length; index += 1)
          ListTile(
            key: Key('$index'),
            tileColor: itemColor,
            title: Text('Item ${_items[index]}'),
          ),
      ],
      onReorder: (int oldIndex, int newIndex) {
        setState(() {
          if (oldIndex < newIndex) {
            newIndex -= 1;
          }
          final int item = _items.removeAt(oldIndex);
          _items.insert(newIndex, item);
        });
      },
    );
  }
}

Activity

  1. exaby73 commented on Sep 5, 2022

    @exaby73
    Member

    I can reproduce this issue.

    Reproducible on

    • Stable (3.3.0)
    • Master (3.4.0-19.0.pre.72)

    Info

    Video
    Code Sample
    import 'package:flutter/material.dart';
    
    void main() => runApp(const ReorderableApp());
    
    class ReorderableApp extends StatelessWidget {
      const ReorderableApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(title: const Text('ReorderableListView Sample')),
            body: const ReorderableExample(),
          ),
        );
      }
    }
    
    class ReorderableExample extends StatefulWidget {
      const ReorderableExample({super.key});
    
      @override
      State<ReorderableExample> createState() => _MyStatefulWidgetState();
    }
    
    class _MyStatefulWidgetState extends State<ReorderableExample> {
      final List<int> _items = List<int>.generate(50, (int index) => index);
    
      @override
      Widget build(BuildContext context) {
        final ColorScheme colorScheme = Theme.of(context).colorScheme;
        final Color oddItemColor = colorScheme.primary.withOpacity(0.05);
        final Color evenItemColor = colorScheme.primary.withOpacity(0.15);
    
        return ReorderableListView(
          reverse: true,
          padding: const EdgeInsets.symmetric(horizontal: 40),
          children: <Widget>[
            for (int index = 0; index < _items.length; index += 1)
              ListTile(
                key: Key('$index'),
                tileColor: _items[index].isOdd ? oddItemColor : evenItemColor,
                title: Text('Item ${_items[index]}'),
              ),
          ],
          onReorder: (int oldIndex, int newIndex) {
            setState(() {
              if (oldIndex < newIndex) {
                newIndex -= 1;
              }
              final int item = _items.removeAt(oldIndex);
              _items.insert(newIndex, item);
            });
          },
        );
      }
    }

    Flutter Doctor

    flutter doctor -v (Stable)
    [✓] Flutter (Channel stable, 3.3.0, on Microsoft Windows [Version 10.0.22000.918], locale en-IN)
        • Flutter version 3.3.0 on channel stable at C:\Users\Nabeel\fvm\versions\stable
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision ffccd96b62 (6 days ago), 2022-08-29 17:28:57 -0700
        • Engine revision 5e9e0e0aa8
        • Dart version 2.18.0
        • DevTools version 2.15.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
        • Android SDK at C:\android-sdk
        • Platform android-33, build-tools 33.0.0
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • CHROME_EXECUTABLE = C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe
    
    [✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.3.2)
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
        • Visual Studio Community 2022 version 17.3.32819.101
        • Windows 10 SDK version 10.0.19041.0
    
    [✓] Android Studio (version 2021.2)
        • Android Studio at C:\Program Files\Android\Android Studio
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    
    [✓] VS Code (version 1.71.0)
        • VS Code at C:\Users\Nabeel\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.46.0
    
    [✓] Connected device (3 available)
        • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22000.918]
        • Chrome (web)      • chrome  • web-javascript • unknown
        • Edge (web)        • edge    • web-javascript • Microsoft Edge 105.0.1343.27
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    flutter doctor -v (Master)
    [✓] Flutter (Channel master, 3.4.0-19.0.pre.72, on Microsoft Windows [Version 10.0.22000.918], locale en-IN)
        • Flutter version 3.4.0-19.0.pre.72 on channel master at C:\Users\Nabeel\fvm\versions\master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 202f5771f4 (6 hours ago), 2022-09-04 20:28:23 -0400
        • Engine revision b94120dfe9
        • Dart version 2.19.0 (build 2.19.0-168.0.dev)
        • DevTools version 2.17.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
        • Android SDK at C:\android-sdk
        • Platform android-33, build-tools 33.0.0
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • CHROME_EXECUTABLE = C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe
    
    [✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.3.2)
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
        • Visual Studio Community 2022 version 17.3.32819.101
        • Windows 10 SDK version 10.0.19041.0
    
    [✓] Android Studio (version 2021.2)
        • Android Studio at C:\Program Files\Android\Android Studio
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    
    [✓] VS Code (version 1.71.0)
        • VS Code at C:\Users\Nabeel\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.46.0
    
    [✓] Connected device (3 available)
        • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22000.918]
        • Chrome (web)      • chrome  • web-javascript • unknown
        • Edge (web)        • edge    • web-javascript • Microsoft Edge 105.0.1343.27
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    on Sep 5, 2022
  3. self-assigned this
    on Sep 6, 2022
  4. added
    r: fixedIssue is closed as already fixed in a newer version
    on Sep 21, 2022
  5. github-actions commented on Oct 5, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  6. locked as resolved and limited conversation to collaborators on Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

found in release: 3.3Found to occur in 3.3found in release: 3.4Found to occur in 3.4frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: animationsThe animations packagep: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions