Skip to content

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

Closed

Description

@maxmitz

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
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<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  List<int> items = List<int>.generate(10, (index) => index);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView.builder(
          itemCount: items.length,
          itemBuilder: (_, index) => Dismissible(
              key: ValueKey<int>(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
Bildschirmaufnahme.2024-01-29.um.17.33.24.mov
Bildschirmaufnahme.2024-01-29.um.17.30.26.mov

Flutter Doctor output

Doctor output
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!```

</details>

Activity

  1. Hyla96 commented on Jan 30, 2024

    @Hyla96

    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)
    
  2. darshankawar commented on Jan 30, 2024

    @darshankawar
    Member

    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.

    RPReplay-Final1706597997.MOV

    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.
    
    
    
    
  3. added
    a: text inputEntering text in a text field or keyboard related problems
    platform-androidAndroid applications specifically
    platform-iosiOS applications specifically
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    f: gesturesflutter/packages/flutter/gestures repository.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-designOwned by Design Languages team
    c: parityWorks on one platform but not another
    and removed
    in triagePresently being triaged by the triage team
    on Jan 30, 2024
  4. added
    P2Important issues not at the top of the work list
    triaged-designTriaged by Design Languages team
    on Feb 1, 2024
  5. added a commit that references this issue on May 1, 2024
    5181086
  6. added
    r: fixedIssue is closed as already fixed in a newer version
    on May 2, 2024
  7. github-actions commented on May 16, 2024

    @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.

  8. locked as resolved and limited conversation to collaborators on May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsc: parityWorks on one platform but not anotherf: gesturesflutter/packages/flutter/gestures repository.found in release: 3.16Found to occur in 3.16found in release: 3.19Found to occur in 3.19frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesplatform-androidAndroid applications specificallyplatform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions