Skip to content

TextField: Bug with Dialog #37798

@yaymalaga

Description

@yaymalaga

Internal: b/147671610

I'm having a bug with the TextField not showing the selection menu (I want to paste text) if used with a modal, like for example a Dialog. This just happens when it is used with a TextEditingController, if you just comment the line 'controller: _controller,' it is working as expected.

Steps to Reproduce

Use the following minimal example to test the bug. Click OPEN and long-pressed the TextField, then the selection menu will appear. Dismiss the modal by pressing outside, then click again OPEN and repeat the operation: the selection menu doesn't appear.

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(),
      title: 'Text Field Test',
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  TextEditingController _controller;

  @override
  void initState() {
    super.initState();
    _controller = TextEditingController();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  void _showDialog(BuildContext context) {
    showDialog<void>(
      context: context,
      builder: (_) => Dialog(
        child: Container(
          padding: const EdgeInsets.all(20),
          child: TextField(
            controller: _controller,
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("TextField Test"),
      ),
      body: Center(
        child: FlatButton(
          child: Text("OPEN"),
          onPressed: () => _showDialog(context),
        ),
      ),
    );
  }
}

I'm using master branch up to date:

[✓] Flutter (Channel master, v1.8.4-pre.129, on Linux, locale en_GB.UTF-8)
    • Flutter version 1.8.4-pre.129 at /home/yaymalaga/Android/flutter
    • Framework revision 5756e2dcd0 (9 hours ago), 2019-08-07 04:50:25 -0400
    • Engine revision 9bfa4f53cd
    • Dart version 2.5.0 (build 2.5.0-dev.1.0 c262cbd414)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
    • Android SDK at /home/yaymalaga/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.1
    • Java binary at: /opt/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] Android Studio (version 3.2)
    • Android Studio at /opt/android-studio
    • Flutter plugin version 31.3.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

Metadata

Metadata

Assignees

Labels

a: text inputEntering text in a text field or keyboard related problemscustomer: mulligan (g3)f: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions