flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.22k stars 27.26k forks source link

DraggableScrollableController.reset closes the sheet after animating to initialChildSize #121954

Open gianmarcocalbi opened 1 year ago

gianmarcocalbi commented 1 year ago

I show a DraggableScrollableSheet with initialChildSize: .5 via showModalBottomSheet. While the sheet is "expanded" to its full extent, animating (animateTo(.5)) or resetting (reset()) the sheet with a DraggableScrollableController causes the sheet to close instead of stopping at .5

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. Tap the "show modal" button
  3. Either drag the sheet upwards or tap the "ANIMATE TO 1" button in order to open the sheet to its full extent
  4. Now tap "RESET": you will see that the sheet gets closed instead of being reset to its initialChildSize (.5)
  5. Retry the step 3. and then tap "ANIMATE TO .5", you will see that the sheet animates to .5 but shortly after it gets closed.

Actual results:

https://user-images.githubusercontent.com/13722041/222929176-89ff1a02-b53d-4c75-bd44-123e355d5c74.mp4


Code sample ```dart import 'package:flutter/material.dart'; class App extends StatefulWidget { const App({super.key}); @override State createState() => _AppState(); } class _AppState extends State { final controller = DraggableScrollableController(); @override void dispose() { controller.dispose(); super.dispose(); } Future showMbs(BuildContext context) async { FocusScope.of(context).unfocus(); await showModalBottomSheet( context: context, useRootNavigator: true, isScrollControlled: true, enableDrag: true, clipBehavior: Clip.antiAlias, backgroundColor: Colors.deepPurple[900], shape: const RoundedRectangleBorder( borderRadius: BorderRadius.zero, ), builder: (ctx) { return DraggableScrollableSheet( controller: controller, initialChildSize: .5, snap: true, snapSizes: const [.5, 1], maxChildSize: 1, minChildSize: .5, expand: false, builder: (ctx, scrollController) { return SafeArea( bottom: false, child: Padding( padding: EdgeInsets.only( top: MediaQuery.of(context).padding.top, ), child: SingleChildScrollView( physics: const ClampingScrollPhysics(), controller: scrollController, child: Padding( padding: const EdgeInsets.all(8), child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ ElevatedButton( onPressed: () { controller.reset(); }, child: const Text('RESET'), ), Padding( padding: const EdgeInsets.only(top: 16), child: ElevatedButton( onPressed: () { controller.animateTo( .5, duration: const Duration(seconds: 1), curve: Curves.easeOutExpo, ); }, child: const Text('ANIMATE TO 0.5'), ), ), Padding( padding: const EdgeInsets.only(top: 16), child: ElevatedButton( onPressed: () { controller.animateTo( 1, duration: const Duration(seconds: 1), curve: Curves.easeOutExpo, ); }, child: const Text('ANIMATE TO 1'), ), ) ], ), ), ), ), ); }, ); }, ); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Main screen'), ), body: Center( child: ElevatedButton( onPressed: () => showMbs(context), child: const Text('Show Modal'), ), ), ); } } ```

Logs ``` [!] Flutter (Channel master, 3.9.0-1.0.pre.48, on macOS 12.6 21G115 darwin-arm64, locale en) • Flutter version 3.9.0-1.0.pre.48 on channel master at /Users/gcalbi/fvm/versions/master ! Warning: `flutter` on your path resolves to /Users/gcalbi/fvm/versions/3.3.10/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/gcalbi/fvm/versions/master. Consider adding /Users/gcalbi/fvm/versions/master/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/gcalbi/fvm/versions/3.3.10/bin/dart, which is not inside your current Flutter SDK checkout at /Users/gcalbi/fvm/versions/master. Consider adding /Users/gcalbi/fvm/versions/master/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision f2f80059ff (17 hours ago), 2023-03-03 23:39:38 -0500 • Engine revision de724e2632 • Dart version 3.0.0 (build 3.0.0-290.0.dev) • DevTools version 2.22.2 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) • Android SDK at /Users/gcalbi/Library/Android/sdk • Platform android-33, build-tools 33.0.1 • Java binary at: /Users/gcalbi/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9514443/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 14.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14B47b • CocoaPods version 1.11.3 [✓] Android Studio (version 2022.1) • Android Studio at /Users/gcalbi/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9514443/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.15+0-b2043.56-8887301) [✓] Android Studio (version 2021.2) • Android Studio at /Users/gcalbi/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/212.5712.43.2112.8815526/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.12+0-b1504.28-7817840) [✓] IntelliJ IDEA Ultimate Edition (version 2021.3.3) • IntelliJ at /Users/gcalbi/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app • Flutter plugin version 69.0.3 • Dart plugin version 213.7371 [✓] IntelliJ IDEA Community Edition (version 2022.2) • IntelliJ at /Users/gcalbi/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/222.3345.118/IntelliJ IDEA CE.app • 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 [✓] IntelliJ IDEA Community Edition (version 2021.2) • IntelliJ at /Users/gcalbi/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/212.4746.92/IntelliJ IDEA CE.app • 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 [✓] IntelliJ IDEA Ultimate Edition (version 2021.3.3) • IntelliJ at /Users/gcalbi/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/213.7172.25/IntelliJ IDEA.app • 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.76.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.60.0 [✓] Connected device (1 available) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 13 (API 33) (emulator) [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ```
darshankawar commented 1 year ago

Thanks for the report. Seeing same behavior as reported using latest versions.

stable, master flutter doctor -v ``` [!] Flutter (Channel stable, 3.7.5, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.7.5 on channel stable at /Users/dhs/documents/fluttersdk/flutter ! Warning: `flutter` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision c07f788888 (7 days ago), 2023-02-22 17:52:33 -0600 • Engine revision 0f359063c4 • Dart version 2.19.2 • DevTools version 2.20.1 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. [!] Flutter (Channel master, 3.9.0-1.0.pre.49, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.9.0-1.0.pre.49 on channel master at /Users/dhs/documents/fluttersdk/flutter ! Warning: `flutter` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision 95387c6621 (28 hours ago), 2023-03-04 16:59:14 -0800 • Engine revision de724e2632 • Dart version 3.0.0 (build 3.0.0-290.0.dev) • DevTools version 2.22.2 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 13C100 • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2) • IntelliJ at /Applications/IntelliJ IDEA.app • Flutter plugin version 65.1.4 • Dart plugin version 213.7228 [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.29.0 [✓] Connected device (3 available) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 15.3.1 19D52 • macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.119 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. ```