Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[IOS]TextField throws assertion error on long press #167798

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

Open
RepliedSage11 opened this issue Apr 25, 2025 · 5 comments
Open

[IOS]TextField throws assertion error on long press #167798

RepliedSage11 opened this issue Apr 25, 2025 · 5 comments
Assignees
Labels
a: text input Entering text in a text field or keyboard related problems found in release: 3.29 Found to occur in 3.29 found in release: 3.32 Found to occur in 3.32 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 platform-ios iOS applications specifically team-text-input Owned by Text Input team triaged-text-input Triaged by Text Input team

Comments

@RepliedSage11
Copy link
Contributor

Steps to reproduce

  1. Enter some text into the TextField
  2. Long press on the text

Expected results

No exception is thrown and a magnifier is shown.

Actual results

Exception is constantly thrown and magnifier does not appear.

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(body: SafeArea(child: Center(child: TextInput()))),
    );
  }
}

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

  @override
  State<TextInput> createState() => _TextInputState();
}

class _TextInputState extends State<TextInput> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 56,
      padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
      decoration: BoxDecoration(
        border: Border.all(color: Colors.black, width: 1),
      ),
      child: TextField(
        decoration: InputDecoration(
          contentPadding: const EdgeInsets.only(bottom: 8),
          label: Text('input'),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration https://github.com/user-attachments/assets/ee6f44af-d1e2-4d9e-a169-38df89ef5101

Logs

Logs
══╡ EXCEPTION CAUGHT BY GESTURE
╞═══════════════════════════════════════════════════════════════════
The following assertion was thrown while handling a gesture:
'dart:ui/math.dart': Failed assertion: line 14 pos 10: '<optimized out>': is not true.

Either the assertion indicates an error in the framework itself, or we should provide
substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

When the exception was thrown, this was the stack:
#2      clampDouble (dart:ui/math.dart:14:10)
#3      RenderEditable._calculateAdjustedCursorOffset
(package:flutter/src/rendering/editable.dart:2458:30)
#4      RenderEditable.calculateBoundedFloatingCursorOffset
(package:flutter/src/rendering/editable.dart:2485:14)
#5      EditableTextState.updateFloatingCursor
(package:flutter/src/widgets/editable_text.dart:3765:14)
#6      TextSelectionGestureDetectorBuilder.onSingleLongTapStart
(package:flutter/src/widgets/text_selection.dart:2597:24)
#7      _TextSelectionGestureDetectorState._handleLongPressStart
(package:flutter/src/widgets/text_selection.dart:3462:35)
#8      LongPressGestureRecognizer._checkLongPressStart.<anonymous closure>
(package:flutter/src/gestures/long_press.dart:702:75)
#9      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:357:24)
#10     LongPressGestureRecognizer._checkLongPressStart
(package:flutter/src/gestures/long_press.dart:702:11)
#11     LongPressGestureRecognizer.didExceedDeadline
(package:flutter/src/gestures/long_press.dart:603:5)
#12     PrimaryPointerGestureRecognizer.didExceedDeadlineWithEvent
(package:flutter/src/gestures/recognizer.dart:746:5)
#13     PrimaryPointerGestureRecognizer.addAllowedPointer.<anonymous closure>
(package:flutter/src/gestures/recognizer.dart:688:41)
#17     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:194:12)
(elided 5 frames from class _AssertionError, class _Timer, and dart:async-patch)

Handler: "onLongPressStart"
Recognizer:
  LongPressGestureRecognizer#747f7
═══════════════════════════════════════════════════════════════════════════════════════════════
═════

Another exception was thrown: 'dart:ui/math.dart': Failed assertion: line 14 pos 10:
'<optimized out>': is not true.
Another exception was thrown: 'dart:ui/math.dart': Failed assertion: line 14 pos 10:
'<optimized out>': is not true.
Another exception was thrown: 'dart:ui/math.dart': Failed assertion: line 14 pos 10:
'<optimized out>': is not true.
Another exception was thrown: 'dart:ui/math.dart': Failed assertion: line 14 pos 10:

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.29.3, on macOS 15.4 24E248 darwin-arm64, locale en-GB) [1,430ms]
    • Flutter version 3.29.3 on channel stable at /Users/alex/workspace/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ea121f8859 (2 weeks ago), 2025-04-11 19:10:07 +0000
    • Engine revision cf56914b32
    • Dart version 3.7.2
    • DevTools version 2.42.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [2.6s]
    • Android SDK at /Users/alex/Library/Android/sdk
    • Platform android-35, build-tools 34.0.0
    • ANDROID_HOME = /Users/alex/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 16.3) [1,286ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16E140
    ! CocoaPods 1.13.0 out of date (1.16.2 is recommended).
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome) [14ms]
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2024.2) [13ms]
    • 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 21.0.3+-79915917-b509.11)

[✓] VS Code (version 1.99.3) [11ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.108.0

[✓] Connected device (4 available) [7.6s]
    • Alex’s iPhone (wireless) (mobile) • 00008130-001A310C0491401C            • ios          • iOS 18.4.1 22E252
    • iPhone 15 Pro (mobile)            • 2348BBCF-963B-412E-9D7E-258EA7E42E24 • ios          • com.apple.CoreSimulator.SimRuntime.iOS-18-4 (simulator)
    • macOS (desktop)                   • macos                                • darwin-arm64 • macOS 15.4 24E248 darwin-arm64
    • Mac Designed for iPad (desktop)   • mac-designed-for-ipad                • darwin       • macOS 15.4 24E248 darwin-arm64
    ! Error: Browsing on the local area network for Alex’s Apple Watch. Ensure the device is unlocked and discoverable via Bluetooth. (code -27)

[✓] Network resources [753ms]
    • All expected network resources are available.

! Doctor found issues in 2 categories.
@RepliedSage11 RepliedSage11 changed the title TextField throws assertion exception on long press TextField throws assertion on long press Apr 25, 2025
@RepliedSage11
Copy link
Contributor Author

Stumbled upon this when trying to reproduce #167720. Seems like it has something to do with the padding and the height of the container.

@maheshj01 maheshj01 added the in triage Presently being triaged by the triage team label Apr 26, 2025
@maheshj01
Copy link
Member

maheshj01 commented Apr 26, 2025

Hey @RepliedSage11, Thanks for filing the issue.
I am unable to reproduce any assertion what platform are you seeing this on?

Screen.Recording.2025-04-25.at.23.19.24.mov
flutter doctor -v

stable

[!] Flutter (Channel stable, 3.29.3, on macOS 15.4 24E248 darwin-arm64, locale en-US) [591ms]
    • Flutter version 3.29.3 on channel stable at /Users/mahesh/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ea121f8859 (5 days ago), 2025-04-11 19:10:07 +0000
    • Engine revision cf56914b32
    • Dart version 3.7.2
    • DevTools version 2.42.3
    • 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 35.0.0) [2.3s]
    • Android SDK at /Users/mahesh/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.3) [1,559ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16E140
    • CocoaPods version 1.16.2

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

[✓] Android Studio (version 2024.3) [152ms]
    • 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 21.0.5+-12932927-b750.29)

[✓] IntelliJ IDEA Community Edition (version 2021.2.1) [150ms]
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

[✓] VS Code (version 1.96.2) [22ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (4 available) [6.5s]
    • iPhone 15 Pro (mobile)          • 7BB5BB29-BA56-4EB1-B698-E6A1AAD138E4 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-18-0 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 15.4 24E248 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 15.4 24E248 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 131.0.6778.265

[✓] Network resources [351ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

@maheshj01 maheshj01 added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 26, 2025
@RepliedSage11
Copy link
Contributor Author

Hi @maheshj01, iOS simulator

@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 Apr 26, 2025
@maheshj01
Copy link
Member

Reproducible on latest stable and the master channel only on IOS device.

Also Long Press does not show magnfication

Screen.Recording.2025-04-28.at.16.42.55.mov
logs
Flutter users should use `flutter pub` instead of `dart pub`.
Performing hot restart...                                               
Restarted application in 820ms.

══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
The following assertion was thrown while handling a gesture:
'dart:ui/math.dart': Failed assertion: line 14 pos 10: '<optimized out>': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=02_bug.yml

When the exception was thrown, this was the stack:
#2      clampDouble (dart:ui/math.dart:14:10)
#3      RenderEditable._calculateAdjustedCursorOffset (package:flutter/src/rendering/editable.dart:2461:30)
#4      RenderEditable.calculateBoundedFloatingCursorOffset (package:flutter/src/rendering/editable.dart:2488:14)
#5      EditableTextState.updateFloatingCursor (package:flutter/src/widgets/editable_text.dart:3583:45)
#6      TextSelectionGestureDetectorBuilder.onSingleLongTapStart
(package:flutter/src/widgets/text_selection.dart:2573:24)
#7      _TextSelectionGestureDetectorState._handleLongPressStart
(package:flutter/src/widgets/text_selection.dart:3438:35)
#8      LongPressGestureRecognizer._checkLongPressStart.<anonymous closure>
(package:flutter/src/gestures/long_press.dart:745:75)
#9      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:345:24)
#10     LongPressGestureRecognizer._checkLongPressStart (package:flutter/src/gestures/long_press.dart:745:11)
#11     LongPressGestureRecognizer.didExceedDeadline (package:flutter/src/gestures/long_press.dart:646:5)
#12     PrimaryPointerGestureRecognizer.didExceedDeadlineWithEvent (package:flutter/src/gestures/recognizer.dart:734:5)
#13     PrimaryPointerGestureRecognizer.addAllowedPointer.<anonymous closure>
(package:flutter/src/gestures/recognizer.dart:676:41)
#17     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:193:12)
(elided 5 frames from class _AssertionError, class _Timer, and dart:async-patch)

Handler: "onLongPressStart"
Recognizer:
  LongPressGestureRecognizer#328a8
════════════════════════════════════════════════════════════════════════════════════════════════════

Another exception was thrown: 'dart:ui/math.dart': Failed assertion: line 14 pos 10: '<optimized out>': is not true.
Another exception was thrown: 'dart:ui/math.dart': Failed assertion: line 14 pos 10: '<optimized out>': is not true.
Another exception was thrown: 'dart:ui/math.dart': Failed assertion: line 14 pos 10: '<optimized out>': is not true.
Another exception was thrown: 'dart:ui/math.dart': Failed assertion: line 14 pos 10: '<optimized out>': is not true.
Another exception was thrown: 'dart:ui/math.dart': Failed assertion: line 14 pos 10: '<optimized out>': is not true.
flutter doctor -v

master

[!] Flutter (Channel master, 3.32.0-1.0.pre.244, on macOS 15.4 24E248 darwin-arm64, locale en-US) [22.8s]
    • Flutter version 3.32.0-1.0.pre.244 on channel master at /Users/mahesh/Development/flutter_master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5574a51f56 (19 hours ago), 2025-04-24 19:34:07 -0400
    • Engine revision 5574a51f56
    • Dart version 3.9.0 (build 3.9.0-52.0.dev)
    • DevTools version 2.45.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 35.0.0) [4.7s]
    • Android SDK at /Users/mahesh/Library/Android/sdk
    • Emulator version 35.2.10.0 (build_id 12414864) (CL:N/A)
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.3) [2.8s]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16E140
    • CocoaPods version 1.16.2

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

[✓] Android Studio (version 2024.3) [129ms]
    • 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 21.0.5+-12932927-b750.29)

[✓] IntelliJ IDEA Community Edition (version 2021.2.1) [126ms]
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

[✓] VS Code (version 1.96.2) [19ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (2 available) [6.5s]
    • macOS (desktop) • macos  • darwin-arm64   • macOS 15.4 24E248 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 131.0.6778.265

[✓] Network resources [1,228ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

stable

[!] Flutter (Channel stable, 3.29.3, on macOS 15.4 24E248 darwin-arm64, locale en-US) [591ms]
    • Flutter version 3.29.3 on channel stable at /Users/mahesh/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ea121f8859 (5 days ago), 2025-04-11 19:10:07 +0000
    • Engine revision cf56914b32
    • Dart version 3.7.2
    • DevTools version 2.42.3
    • 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 35.0.0) [2.3s]
    • Android SDK at /Users/mahesh/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.3) [1,559ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16E140
    • CocoaPods version 1.16.2

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

[✓] Android Studio (version 2024.3) [152ms]
    • 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 21.0.5+-12932927-b750.29)

[✓] IntelliJ IDEA Community Edition (version 2021.2.1) [150ms]
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

[✓] VS Code (version 1.96.2) [22ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (4 available) [6.5s]
    • iPhone 15 Pro (mobile)          • 7BB5BB29-BA56-4EB1-B698-E6A1AAD138E4 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-18-0 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 15.4 24E248 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 15.4 24E248 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 131.0.6778.265

[✓] Network resources [351ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

@maheshj01 maheshj01 added a: text input Entering text in a text field or keyboard related problems platform-ios iOS applications specifically has reproducible steps The issue has been confirmed reproducible and is ready to work on team-text-input Owned by Text Input team found in release: 3.29 Found to occur in 3.29 found in release: 3.32 Found to occur in 3.32 and removed in triage Presently being triaged by the triage team labels Apr 28, 2025
@maheshj01 maheshj01 changed the title TextField throws assertion on long press [IOS]TextField throws assertion error on long press Apr 28, 2025
@RepliedSage11
Copy link
Contributor Author

RepliedSage11 commented Apr 29, 2025

final double bottomBound =
math.min(size.height, _textPainter.height) -
preferredLineHeight +
floatingCursorAddedMargin.bottom;

I am not sure why bottomBound is calculated like it is, but it ends up being negative in this situation and fails the assert.

Updating this to always use the _textPainter.height fixed it, but I am not sure if anything else is broken now.

final double bottomBound =
        _textPainter.height -
        preferredLineHeight +
        floatingCursorAddedMargin.bottom;

@justinmc justinmc added P2 Important issues not at the top of the work list triaged-text-input Triaged by Text Input team labels May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: text input Entering text in a text field or keyboard related problems found in release: 3.29 Found to occur in 3.29 found in release: 3.32 Found to occur in 3.32 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 platform-ios iOS applications specifically team-text-input Owned by Text Input team triaged-text-input Triaged by Text Input team
Projects
None yet
Development

No branches or pull requests

4 participants