Skip to content

Implementations of TextEditingControllers throw error #148692

@FMorschel

Description

@FMorschel

Steps to reproduce

  1. Latest Flutter version environment (in 3.19.6 this API was external).
  2. Create a project and extend TextEditingController (example below).
  3. Trigger the error by clicking/tapping on the TextField

Expected results

No errors.

Actual results

More details in log below:

NoSuchMethodError: tried to call a non-function, such as null:
'core.NoSuchMethodError.withInvocation'

When the exception was thrown, this was the stack:
packages/floating_overlay/main.dart 77:46                           [_isSelectionWithinTextBounds]

Code sample

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

void main() => runApp(
      MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: const Text('Example'),
          ),
          body: TextField(
            controller: DelegatingTextEditingController(),
          ),
        ),
      ),
    );

class DelegatingTextEditingController implements TextEditingController {
  DelegatingTextEditingController([
    TextEditingController? controller,
  ]) : _text = controller ?? TextEditingController();

  final TextEditingController _text;

  @override
  void dispose() {
    _text.dispose();
  }

  @override
  void addListener(VoidCallback listener) {
    _text.addListener(listener);
  }

  @override
  void notifyListeners() {
    _text.notifyListeners();
  }

  @override
  void removeListener(VoidCallback listener) {
    _text.removeListener(listener);
  }

  @override
  TextSpan buildTextSpan({
    required bool withComposing,
    required BuildContext context,
    TextStyle? style,
  }) =>
      _text.buildTextSpan(
        context: context,
        style: style,
        withComposing: withComposing,
      );

  @override
  void clear() => _text.clear();

  @override
  void clearComposing() => _text.clearComposing();

  @override
  TextSelection get selection => _text.selection;
  @override
  set selection(TextSelection newSelection) => _text.selection = newSelection;

  @override
  String get text => _text.text;
  @override
  set text(String newText) => _text.text = newText;

  @override
  TextEditingValue get value => _text.value;
  @override
  set value(TextEditingValue newValue) => _text.value = newValue;

  @override
  bool get hasListeners => _text.hasListeners;
}

Screenshots or Video

No response

Logs

Logs
══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
The following JSNoSuchMethodError was thrown while handling a gesture:
NoSuchMethodError: tried to call a non-function, such as null:
'core.NoSuchMethodError.withInvocation'

When the exception was thrown, this was the stack:
packages/floating_overlay/main.dart 77:46                           [_isSelectionWithinTextBounds]
packages/flutter/src/widgets/editable_text.dart 3934:28             [_handleSelectionChanged]
packages/flutter/src/widgets/editable_text.dart 4184:7              [_formatAndSetValue]
packages/flutter/src/widgets/editable_text.dart 4554:5              userUpdateTextEditingValue
packages/flutter/src/rendering/editable.dart 719:5                  [_setTextEditingValue]
packages/flutter/src/rendering/editable.dart 738:5                  [_setSelection]
packages/flutter/src/rendering/editable.dart 2088:5                 selectPositionAt
packages/flutter/src/rendering/editable.dart 2065:5                 selectPosition
packages/flutter/src/widgets/text_selection.dart 2260:9             onTapDown
packages/flutter/src/widgets/text_selection.dart 3283:23            [_handleTapDown]
packages/flutter/src/gestures/tap_and_drag.dart 1179:41             <fn>
packages/flutter/src/gestures/recognizer.dart 344:24                invokeCallback
packages/flutter/src/gestures/tap_and_drag.dart 1179:7              [_checkTapDown]
packages/flutter/src/gestures/tap_and_drag.dart 982:7               acceptGesture
packages/flutter/src/gestures/arena.dart 269:10                     [_resolveByDefault]
packages/flutter/src/gestures/arena.dart 249:31                     callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                    _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                     _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7  <fn>

Handler: "onTapDown"
Recognizer:
  TapAndPanGestureRecognizer#aceca
════════════════════════════════════════════════════════════════════════════════════════════════════

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.19.6, on Microsoft Windows [Version 10.0.22621.3007], locale pt-BR)
    • Flutter version 3.19.6 on channel stable at C:\Users\felip_0vh5fa6\.puro\envs\stable\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (11 days ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.34.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Users\felip_0vh5fa6\AppData\Local\Programs\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.4.5)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.4.33403.182
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2023.2)
    • Android Studio at C:\Users\felip_0vh5fa6\AppData\Local\Programs\Android Studio
    • 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 17.0.9+0--11185874)

[√] IntelliJ IDEA Community Edition (version 2024.1)
    • IntelliJ at C:\Users\felip_0vh5fa6\AppData\Local\Programs\IntelliJ IDEA Community Edition
    • Flutter plugin version 78.5.1
    • Dart plugin version 241.15845

[√] VS Code (version 1.89.1)
    • VS Code at C:\Users\felip_0vh5fa6\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.78.0

[√] VS Code (version 1.88.0-insider)
    • VS Code at C:\Users\felip_0vh5fa6\AppData\Local\Programs\Microsoft VS Code Insiders
    • Flutter extension version 3.64.0

[√] Connected device (4 available)
    • SM S918B (mobile) • fmorschel-phone:33587 • android-arm64  • Android 14 (API 34)
    • Windows (desktop) • windows               • windows-x64    • Microsoft Windows [Version 10.0.22621.3007]
    • Chrome (web)      • chrome                • web-javascript • Google Chrome 125.0.6422.60
    • Edge (web)        • edge                  • web-javascript • Microsoft Edge 124.0.2478.80

[√] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: regressionIt was better in the past than it is nowf: material designflutter/packages/flutter/material repository.found in release: 3.22Found to occur in 3.22frameworkflutter/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