Skip to content

App throws LateInitializationError when re-focusing text field #74347

@LongCatIsLooong

Description

@LongCatIsLooong
Sample App
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Sample',
      home: Scaffold(
        body: Center(
          child: TextField(),
        ),
      ),
    );
  }
}

Steps to repro:

  1. Run the sample app

  2. Focus the text field by tapping on it.

  3. Press R to hot restart the app. The software keyboard stays.

  4. Type a few characters using the software keyboard without re-focusing the text field.

  5. Focus the text field. The app throws the following exception:

Performing hot restart...                                               
Restarted application in 849ms.

══╡ EXCEPTION CAUGHT BY FOUNDATION LIBRARY ╞════════════════════════════════════════════════════════
The following LateError was thrown while dispatching notifications for FocusNode:
LateInitializationError: Field '_instance@393206165' has been assigned during initialization.

When the exception was thrown, this was the stack:
#0      TextInput._instance (package:flutter/src/services/text_input.dart)
#1      TextInput.attach (package:flutter/src/services/text_input.dart:1348:5)
#2      EditableTextState._openInputConnection (package:flutter/src/widgets/editable_text.dart:2014:21)
#3      EditableTextState._openOrCloseInputConnectionIfNeeded (package:flutter/src/widgets/editable_text.dart:2049:7)
#4      EditableTextState._handleFocusChanged (package:flutter/src/widgets/editable_text.dart:2386:5)
#5      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:243:25)
#6      FocusNode._notify (package:flutter/src/widgets/focus_manager.dart:1052:5)
#7      FocusManager._applyFocusChange (package:flutter/src/widgets/focus_manager.dart:1771:12)
(elided 10 frames from dart:async)

The FocusNode sending notification was:
  FocusNode#1b534([PRIMARY FOCUS])
════════════════════════════════════════════════════════════════════════════════════════════════════

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: null-safetySupport for Dart's null safety featurea: text inputEntering text in a text field or keyboard related problemsc: crashStack traces logged to the consoleframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions