Repository navigation
TextField: Bug with Dialog #37798
Copy link
Copy link
Closed
Labels
a: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemscustomer: mulligan (g3)frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packages
Milestone
Description
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)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
a: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemscustomer: mulligan (g3)frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packages
Activity
justinmc commentedon Aug 8, 2019
I was able to reproduce this using the steps given. Very strange! I'll try to look into this when I have time and see why it's not showing up.
irfantusneem commentedon Jan 7, 2020
It looks like this can be reproduced in other containers even when there is no controller set.
jason-simmons commentedon Jan 10, 2020
Reproduced this in the affected app. The toolbar is not showing because
EditableTextStatehas a null_selectionOverlayat the time of theshowToolbarcall.Ordinarily
_selectionOverlaywould be constructed by a_handleSelectionChangedcall triggered by the tap into the text field that sets the caret position. But in this case, theRenderEditableselection is being set to the zero position due to interactions with the text service. When the tap occursRenderEditable._handleSelectionChangethinks the selection already has the right value and does not make the callback intoEditableTextState._handleSelectionChanged._selectionOverlayis never set, and the toolbar does not show.@justinmc One potential workaround would be creating
_selectionOverlayinEditableTextState._handleFocusChangedwhen the text field acquires the focus.justinmc commentedon Jan 10, 2020
Thanks for the investigation Jason. I actually can't seem to reproduce this myself! I'm using master and tried on the Android emulator and a physical iOS device. Maybe I need to try a physical Android device.
I tap Open, then directly long press the field, and I see the selection menu. Then I tap the background to close the modal, tap Open again, and directly long press the field again. The selection menu shows again without a problem. If I print
_selectionOverlayinshowToolbarin EditableTextState, it is never null.gliese667c commentedon Jan 10, 2020
Same problem on physical iOS device.
justinmc commentedon Jan 10, 2020
@gliese667c Are you on master?
justinmc commentedon Jan 16, 2020
I was able to reproduce this bug, not by using a Dialog, but due to setting the initial selection to 0,0. I fixed it in #49000. Here's a basic app that reproduces it.
If this doesn't cover anyone's problem here, let me know.
github-actions commentedon Aug 23, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.