Skip to content

Selecting text in readOnly TextField on iOS throws assertion exception #170521

@Amir-P

Description

@Amir-P

Original issue: fleather-editor/fleather#513

Steps to reproduce

  1. Create a read-only TextField
  2. Select part of the text to show the context menu

Expected results

It should show the context menu.

Actual results

Throws an assertion exception and no context menu.

Code sample

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

void main() {
  runApp(MaterialApp(home: const HomePage()));
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: TextField(
        readOnly: true,
        controller: TextEditingController(text: 'Test'),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building SystemContextMenu(dirty, dependencies: [MediaQuery, _LocalizationsScope-[GlobalKey#643d1]], state: _SystemContextMenuState#fbbfc):
Currently, the system context menu can only be shown for an active text input connection
'package:flutter/src/services/text_input.dart':
Failed assertion: line 2734 pos 7: 'TextInput._instance._currentConnection != null'

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

The relevant error-causing widget was:
    MaterialApp MaterialApp:file:///lib/main.dart:20:41

When the exception was thrown, this was the stack:
#2      SystemContextMenuController.showWithItems (package:flutter/src/services/text_input.dart:2734:7)
text_input.dart:2734
#3      _SystemContextMenuState.build (package:flutter/src/widgets/system_context_menu.dart:167:36)
system_context_menu.dart:167
#4      StatefulElement.build (package:flutter/src/widgets/framework.dart:5823:27)
framework.dart:5823
#5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5715:15)
framework.dart:5715
#6      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5874:11)
framework.dart:5874
#7      Element.rebuild (package:flutter/src/widgets/framework.dart:5427:7)
framework.dart:5427
#8      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5697:5)
framework.dart:5697
#9      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5865:11)
framework.dart:5865
#10     ComponentElement.mount (package:flutter/src/widgets/framework.dart:5691:5)
framework.dart:5691
...     Normal element mounting (64 frames)
#74     Element.inflateWidget (package:flutter/src/widgets/framework.dart:4539:16)
framework.dart:4539
#75     MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:7159:36)
framework.dart:7159
#76     Element.updateChild (package:flutter/src/widgets/framework.dart:4004:18)
framework.dart:4004
#77     Element.updateChildren (package:flutter/src/widgets/framework.dart:4201:11)
framework.dart:4201
#78     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:7192:17)
framework.dart:7192
#79     Element.updateChild (package:flutter/src/widgets/framework.dart:3982:15)
framework.dart:3982
#80     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5738:16)
framework.dart:5738
#81     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5874:11)
framework.dart:5874
#82     Element.rebuild (package:flutter/src/widgets/framework.dart:5427:7)
framework.dart:5427
#83     BuildScope._tryRebuild (package:flutter/src/widgets/framework.dart:2694:15)
framework.dart:2694
#84     BuildScope._flushDirtyElements (package:flutter/src/widgets/framework.dart:2752:11)
framework.dart:2752
#85     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:3056:18)
framework.dart:3056
#86     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1240:21)
binding.dart:1240
#87     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:495:5)
binding.dart:495
#88     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1438:15)
binding.dart:1438
#89     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1351:9)
binding.dart:1351
#90     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1204:5)
binding.dart:1204
#91     _invoke (dart:ui/hooks.dart:331:13)
hooks.dart:331
#92     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:444:5)
platform_dispatcher.dart:444
#93     _drawFrame (dart:ui/hooks.dart:303:31)
hooks.dart:303
(elided 2 frames from class _AssertionError)

════════════════════════════════════════════════════════════════════════════════

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.32.0, on macOS 15.4 24E248 darwin-arm64, locale
    en-US) [715ms]
    • Flutter version 3.32.0 on channel stable at
      /fvm/versions/3.32.0
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision be698c48a6 (3 weeks ago), 2025-05-19 12:59:14 -0700
    • Engine revision 1881800949
    • Dart version 3.8.0
    • DevTools version 2.45.1

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    [10.6s]
    • Android SDK at /SDK
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = /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+-13047016-b750.29)
    • All Android licenses accepted.

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

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

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

[✓] VS Code (version 1.100.3) [10ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.112.0

[✓] Connected device (4 available) [13.3s]
    • iPhone 16 Pro Max (mobile)        • A640AB5F-F030-4C86-B622-7A278C070CC9 •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-18-3 (simulator)
    • macOS (desktop)                   • macos                                •
      darwin-arm64   • macOS 15.4 24E248 darwin-arm64
    • Chrome (web)                      • chrome                               •
      web-javascript • Google Chrome 137.0.7151.70
    ! Error: Browsing on the local area network for iPhone. Ensure the device is
      unlocked and attached with a cable or associated with the same local area
      network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code
      -27)

[✓] Network resources [6.8s]
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work lista: error messageError messages from the Flutter frameworka: text inputEntering text in a text field or keyboard related problemsfound in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-text-inputOwned by Text Input teamtriaged-text-inputTriaged by Text Input team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions