Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizontal AnimatedSliverLists do not animate #100931

Open
benthillerkus opened this issue Mar 28, 2022 · 3 comments
Open

Horizontal AnimatedSliverLists do not animate #100931

benthillerkus opened this issue Mar 28, 2022 · 3 comments
Labels
a: animation Animation APIs f: scrolling Viewports, list views, slivers, etc. found in release: 2.10 Found to occur in 2.10 found in release: 2.13 Found to occur in 2.13 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list team-framework Owned by Framework team triaged-framework Triaged by Framework team

Comments

@benthillerkus
Copy link

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. Press the Add button to add a lot of FlutterLogos
  3. Press the Change Direction button...

Expected results:

With both horizontal and vertical scroll direction, adding elements is animated. Also, in both directions the content should be scrollable if it overflows.

Actual results:

Everything works with scrollDirection == Axis.vertical, but with scrollDirection == Axis.horizontal new elements won't animate in and the content will just overflow, without the user being able to scroll.

Code sample

Example on Dartpad

// Press add to new elements to the list
// Press the other button to change the direction from vertial to horizontal
// Observe that the animations break and that the content won't scroll either

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.from(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurpleAccent),
      ),
      darkTheme: ThemeData.from(
        colorScheme: ColorScheme.fromSeed(
            seedColor: Colors.deepPurpleAccent, brightness: Brightness.dark)),
      themeMode: ThemeMode.system,
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _listKey = GlobalKey<SliverAnimatedListState>();
  var _scrollDirection = Axis.vertical;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      persistentFooterButtons: [
        TextButton.icon(
          label: const Text("Add"),
          icon: const Icon(Icons.add),
          onPressed: () => _listKey.currentState?.insertItem(0),
        ),
        TextButton.icon(
            label: const Text("Change direction"),
            icon: const Icon(Icons.rotate_left),
            onPressed: () => setState(() => _scrollDirection =
                _scrollDirection == Axis.vertical
                    ? Axis.horizontal
                    : Axis.vertical))
      ],
      body: CustomScrollView(scrollDirection: _scrollDirection, slivers: [
        SliverAnimatedList(
            key: _listKey,
            itemBuilder: (BuildContext context, int index,
                    Animation<double> animation) =>
                SizeTransition(
                    sizeFactor: animation,
                    child: const FlutterLogo()))
      ]),
    );
  }
}
Logs

Analyzing manage_icons...                                               
No issues found! (ran in 1.7s)
[✓] Flutter (Channel stable, 2.10.4, on Microsoft Windows [Version 10.0.19044.1586], locale de-DE)
    • Flutter version 2.10.4 at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c860cba910 (4 days ago), 2022-03-25 00:23:12 -0500
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\Bent\AppData\Local\Android\sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.11)
    • Visual Studio at O:\Programs\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.32228.343
    • Windows 10 SDK version 10.0.17763.0

[✓] Android Studio (version 2020.3)
    • 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.10+0-b96-7249189)

[✓] IntelliJ IDEA Ultimate Edition (version 2021.2)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2020.3
    • 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

[✓] VS Code (version 1.65.2)
    • VS Code at C:\Users\Bent\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 2.23.0

[✓] Connected device (1 available)
    • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19044.1586]

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

chrome_2022-03-29_00-25-37

@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label Mar 29, 2022
@danagbemava-nc danagbemava-nc changed the title Horizontal AnimatedSliverLists neither scroll nor animate Horizontal AnimatedSliverLists do not animate Mar 29, 2022
@danagbemava-nc
Copy link
Member

danagbemava-nc commented Mar 29, 2022

Hi @benthillerkus, the list not scrolling when it is horizontal is due to https://docs.flutter.dev/release/breaking-changes/default-scroll-behavior-drag. If you follow the doc, you can make it scroll horizontally.

I can reproduce the listview not animating when the scrollDirection is horizontal. Labeling for further investigation.

video
Screen.Recording.2022-03-29.at.08.04.48.mov
complete sample
// Press add to add new elements to the list
// Press the other button to change the direction from vertical to horizontal
// Observe that the animations break and that the content won't scroll either

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

class MyCustomScrollBehavior extends MaterialScrollBehavior {
  // Override behavior methods and getters like dragDevices
  @override
  Set<PointerDeviceKind> get dragDevices => { 
    PointerDeviceKind.touch,
    PointerDeviceKind.mouse,
    // etc.
  };
}

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      scrollBehavior: MyCustomScrollBehavior(),
      theme: ThemeData.from(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurpleAccent),
      ),
      darkTheme: ThemeData.from(
        colorScheme: ColorScheme.fromSeed(
            seedColor: Colors.deepPurpleAccent, brightness: Brightness.dark),
      ),
      themeMode: ThemeMode.system,
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _listKey = GlobalKey<SliverAnimatedListState>();
  var _scrollDirection = Axis.vertical;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      persistentFooterButtons: [
        TextButton.icon(
          label: const Text("Add"),
          icon: const Icon(Icons.add),
          onPressed: () => _listKey.currentState?.insertItem(0),
        ),
        TextButton.icon(
          label: const Text("Change direction"),
          icon: const Icon(Icons.rotate_left),
          onPressed: () => setState(() => _scrollDirection =
              _scrollDirection == Axis.vertical
                  ? Axis.horizontal
                  : Axis.vertical),
        )
      ],
      body: CustomScrollView(
        scrollDirection: _scrollDirection,
        slivers: [
          SliverAnimatedList(
            key: _listKey,
            itemBuilder: (BuildContext context, int index,
                    Animation<double> animation) =>
                SizeTransition(
              sizeFactor: animation,
              child: const FlutterLogo(),
            ),
          )
        ],
      ),
    );
  }
}
flutter doctor -v
[✓] Flutter (Channel stable, 2.10.4, on macOS 12.2.1 21D62 darwin-arm, locale en-GB)
    • Flutter version 2.10.4 at /Users/nexus/dev/sdks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c860cba910 (4 days ago), 2022-03-25 00:23:12 -0500
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-32, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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.11+0-b60-7772763)

[☠] IntelliJ IDEA Community Edition (the doctor check crashed)
    ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at https://github.com/flutter/flutter/issues.
    ✗ FormatException: Unexpected extension byte (at offset 5)
    • #0      _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1789:7)
      #1      Utf8Decoder.convert (dart:convert/utf.dart:351:42)
      #2      InputStream.readString (package:archive/src/util/input_stream.dart:207:30)
      #3      new ZipDirectory.read (package:archive/src/zip/zip_directory.dart:40:30)
      #4      ZipDecoder.decodeBuffer (package:archive/src/zip_decoder.dart:19:30)
      #5      ZipDecoder.decodeBytes (package:archive/src/zip_decoder.dart:14:12)
      #6      IntelliJPlugins._findPluginXml (package:flutter_tools/src/intellij/intellij.dart:130:44)
      #7      IntelliJPlugins._readPackageVersion (package:flutter_tools/src/intellij/intellij.dart:141:40)
      #8      IntelliJPlugins.validatePackage (package:flutter_tools/src/intellij/intellij.dart:63:35)
      #9      IntelliJValidator.validate (package:flutter_tools/src/intellij/intellij_validator.dart:103:15)
      #10     asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:111:32)
      #11     asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:109:18)
      #12     _rootRun (dart:async/zone.dart:1426:13)
      #13     _CustomZone.run (dart:async/zone.dart:1328:19)
      #14     _runZoned (dart:async/zone.dart:1861:10)
      #15     runZonedGuarded (dart:async/zone.dart:1849:12)
      #16     runZoned (dart:async/zone.dart:1780:12)
      #17     asyncGuard (package:flutter_tools/src/base/async_guard.dart:109:3)
      #18     Doctor.startValidatorTasks (package:flutter_tools/src/doctor.dart:205:9)
      #19     Doctor.diagnose (package:flutter_tools/src/doctor.dart:309:47)
      #20     DoctorCommand.runCommand (package:flutter_tools/src/commands/doctor.dart:50:48)
      #21     FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1320:12)
      <asynchronous suspension>
      #22     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1161:27)
      <asynchronous suspension>
      #23     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
      <asynchronous suspension>
      #24     CommandRunner.runCommand (package:args/command_runner.dart:209:13)
      <asynchronous suspension>
      #25     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9)
      <asynchronous suspension>
      #26     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
      <asynchronous suspension>
      #27     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
      <asynchronous suspension>
      #28     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
      <asynchronous suspension>
      #29     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
      <asynchronous suspension>
      #30     main (package:flutter_tools/executable.dart:94:3)
      <asynchronous suspension>


[✓] VS Code (version 1.65.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.36.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 12.2.1 21D62 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 99.0.4844.83

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
[✓] Flutter (Channel master, 2.13.0-0.0.pre.297, on macOS 12.2.1 21D62 darwin-arm, locale en-GB)
    • Flutter version 2.13.0-0.0.pre.297 at /Users/nexus/dev/sdks/flutters
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b4325b68a2 (3 hours ago), 2022-03-28 21:57:44 -0700
    • Engine revision e21d49ae26
    • Dart version 2.17.0 (build 2.17.0-246.0.dev)
    • DevTools version 2.11.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-32, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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.11+0-b60-7772763)

[✓] IntelliJ IDEA Community Edition (version 2021.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin version 213.5744.122

[✓] VS Code (version 1.65.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.36.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 12.2.1 21D62 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 99.0.4844.83

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

@danagbemava-nc danagbemava-nc added has reproducible steps The issue has been confirmed reproducible and is ready to work on framework flutter/packages/flutter repository. See also f: labels. a: animation Animation APIs f: scrolling Viewports, list views, slivers, etc. found in release: 2.10 Found to occur in 2.10 found in release: 2.13 Found to occur in 2.13 and removed in triage Presently being triaged by the triage team labels Mar 29, 2022
@goderbauer goderbauer added the P2 Important issues not at the top of the work list label Mar 30, 2022
@xu-baolin
Copy link
Member

@benthillerkus Hi, thanks for reporting, you can special the item's axis for your proposal:

      body: CustomScrollView(
        scrollDirection: _scrollDirection,
        slivers: [
          SliverAnimatedList(
            key: _listKey,
            itemBuilder: (BuildContext context, int index,
                Animation<double> animation) {
              print('index $index $animation');
              return SizeTransition(
                sizeFactor: animation,
                axis: _scrollDirection,
                child: const FlutterLogo(),
              );
            },
          )
        ],
      ),

@xu-baolin xu-baolin added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 6, 2022
@benthillerkus
Copy link
Author

Yeah, at some point I got there too 😅

I think the situation could be improved, though, by

  1. adding the axis parameter to the examples for the AnimatedList and the SliverAnimatedList. The behavior makes conceptually sense if you know that the SizeTransition only shrinks one side -- which you can pick with the axis parameter. If you don't know that, I think one would assume that the SizeTransition changes the entire size proportionally.
  2. maybe having ScrollViews have an InheritedWidget that provides a ScrollDirection.of(context), which could be the default value for axis?

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 9, 2022
@flutter-triage-bot flutter-triage-bot bot added team-framework Owned by Framework team triaged-framework Triaged by Framework team labels Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: animation Animation APIs f: scrolling Viewports, list views, slivers, etc. found in release: 2.10 Found to occur in 2.10 found in release: 2.13 Found to occur in 2.13 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list team-framework Owned by Framework team triaged-framework Triaged by Framework team
Projects
None yet
Development

No branches or pull requests

4 participants