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
162.22k stars 26.65k forks source link

The behavior of Dismissible with TextFormFields is different for Android and iOS #142447

Closed maxmitz closed 2 weeks ago

maxmitz commented 3 months ago

Steps to reproduce

  1. Run the code sample on Android and iOS.
  2. Dismiss an item with the red SizedBox and the TextFormField part.

Expected results

The behavior should be the same on iOS and Android. In my opinion, it should on both platforms be possible to dismiss by sliding the TextFormField.

If the TextField takes up the entire Dismissible, then it will handle the gesture. This is also not true for iOS.

Actual results

On Android you can dismiss an item by touching the red SizedBox part but also the TextFormField part. On iOS you can dismiss an item only by touching the red SizedBox part but not the TextFormField part.

Code sample

Code sample ```dart import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp( home: MyHomePage(), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { List items = List.generate(10, (index) => index); @override Widget build(BuildContext context) { return Scaffold( body: ListView.builder( itemCount: items.length, itemBuilder: (_, index) => Dismissible( key: ValueKey(items[index]), onDismissed: (DismissDirection direction) { setState(() { items.removeAt(index); }); }, child: Row( children: [ Container( width: 50, height: 30, color: Colors.red, ), SizedBox( width: 200, child: TextFormField( initialValue: items[index].toString(), )), Container( width: 50, height: 30, color: Colors.red, ), ], ))), ); } } ```

Screenshots or Video

Screenshots / Video demonstration https://github.com/flutter/flutter/assets/72440045/f13c2d0b-d510-48a0-8f3a-cbe597ac52cd https://github.com/flutter/flutter/assets/72440045/2b4c3ae1-8b4c-42c0-9407-3d3ca6e2c95a

Flutter Doctor output

Doctor output ```console Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.16.5, on macOS 14.0 23A344 darwin-arm64, locale de-DE) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) [✓] Xcode - develop for iOS and macOS (Xcode 15.0) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.3) [✓] VS Code (version 1.85.1) [✓] Connected device (5 available) [✓] Network resources • No issues found!```
Hyla96 commented 3 months ago

The issue has something to do with the field implementing gestures for the text selection.

If you replace the field with a Gesture detector and pass onHorizontalDragUpdate you get the same behavior you get on iOS (but you get it on both platforms). (It doesn't happen if you define only onTap)

I believe that the field widget implements some platform-specific logic that defines (only for iOS) the dragging behavior for the RawGestureDetector underneath.

My results by running gesture arena:

Android

I/flutter ( 6180): Gesture arena 1    ❙ ★ Opening new gesture arena.
I/flutter ( 6180): Gesture arena 1    ❙ Adding: LongPressGestureRecognizer#c7fd1(debugOwner: _TextSelectionGestureDetectorState#74587, state: ready)
I/flutter ( 6180): Gesture arena 1    ❙ Adding: TapAndHorizontalDragGestureRecognizer#bc5ef(debugOwner: _TextSelectionGestureDetectorState#74587)
I/flutter ( 6180): Gesture arena 1    ❙ Adding: HorizontalDragGestureRecognizer#bb172(debugOwner: GestureDetector, start behavior: start)
I/flutter ( 6180): Gesture arena 1    ❙ Adding: VerticalDragGestureRecognizer#ba151(start behavior: start)
I/flutter ( 6180): Gesture arena 1    ❙ Closing with 4 members.
I/flutter ( 6180): Gesture arena 1    ❙ Accepting: HorizontalDragGestureRecognizer#bb172(debugOwner: GestureDetector, start behavior: start)
I/flutter ( 6180): Gesture arena 1    ❙ Self-declared winner: HorizontalDragGestureRecognizer#bb172(debugOwner: GestureDetector, start behavior: start)

iOS

flutter: Gesture arena 13   ❙ ★ Opening new gesture arena.
flutter: Gesture arena 13   ❙ Adding: LongPressGestureRecognizer#8310a(debugOwner: _TextSelectionGestureDetectorState#bcacb, state: ready)
flutter: Gesture arena 13   ❙ Adding: TapAndHorizontalDragGestureRecognizer#5e5b9(debugOwner: _TextSelectionGestureDetectorState#bcacb)
flutter: Gesture arena 13   ❙ Adding: HorizontalDragGestureRecognizer#e568a(debugOwner: GestureDetector, start behavior: start)
flutter: Gesture arena 13   ❙ Adding: VerticalDragGestureRecognizer#fccbd(start behavior: start)
flutter: Gesture arena 13   ❙ Closing with 4 members.
flutter: Gesture arena 13   ❙ Rejecting: LongPressGestureRecognizer#8310a(debugOwner: _TextSelectionGestureDetectorState#bcacb, state: possible)
flutter: Gesture arena 13   ❙ Accepting: TapAndHorizontalDragGestureRecognizer#5e5b9(debugOwner: _TextSelectionGestureDetectorState#bcacb)
flutter: Gesture arena 13   ❙ Self-declared winner: TapAndHorizontalDragGestureRecognizer#5e5b9(debugOwner: _TextSelectionGestureDetectorState#bcacb)
darshankawar commented 3 months ago

Thanks for the report. I was able to see the same behavior as observed on both platforms. The same is noticed using the official code sample (by replacing Text with TextField).

I looked at native iOS app (Reminders) and observed that the swiping from center area which is clickable, is possible.

https://github.com/flutter/flutter/assets/67046386/2951a140-7958-4727-9f72-a9489603efe2

If the TextField takes up the entire Dismissible, then it will handle the gesture. This is also not true for iOS.

Updated the code from above link and running on both platform still gives the same behavior as reported.

stable, master flutter doctor -v ``` [!] Flutter (Channel stable, 3.16.8, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.16.8 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 67457e669f (2 days ago), 2024-01-16 16:22:29 -0800 • Engine revision 6e2ea58a5c • Dart version 3.2.5 • DevTools version 2.28.5 • 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.19.0-13.0.pre.29, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.19.0-13.0.pre.29 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 5c64d0370b (2 hours ago), 2024-01-29 22:21:25 -0500 • Engine revision ed73d40a8c • Dart version 3.4.0 (build 3.4.0-82.0.dev) • DevTools version 2.31.0 • 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 30.0.3) • Android SDK at /Users/dhs/Library/Android/sdk ✗ cmdline-tools component is missing Run `path/to/sdkmanager --install "cmdline-tools;latest"` See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details. [✓] 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. ```
github-actions[bot] commented 22 hours ago

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.