[英]Flutter app freezes when a TextField or TextFormField is selected
I have a Flutter app that is functioning properly in all respects except when I select a TextField (or TextFormField).我有一个 Flutter 应用程序,它在所有方面都正常运行,除非我 select 是一个 TextField(或 TextFormField)。 When I select the TextField, the cursor blinks in the TextField, but I can't type anything AND all other buttons like the floatingActionButton and the back button in the AppBar quit working.
当我 select TextField 时,cursor 在 TextField 中闪烁,但我无法输入任何内容,并且 AppBar 中的所有其他按钮(如 floatingActionButton 和后退按钮)都停止工作。 Essentially, the app appears to be frozen, but I don't get any error messages.
本质上,该应用程序似乎被冻结,但我没有收到任何错误消息。
After numerous attempts to fix the problem in two different pages that contain FocusNodes and TextEditingControllers, I went back to square one by incorporating a new page with code straight from Flutter's website, but the TextField in this barebones code still locks up the app.在多次尝试解决包含 FocusNodes 和 TextEditingControllers 的两个不同页面中的问题后,我通过直接从 Flutter 网站合并一个新页面的代码回到了原点,但是这个准系统代码中的 TextField 仍然锁定了应用程序。
import 'package:flutter/material.dart';
class EventDetailForm extends StatefulWidget {
static const String routeName = "/events/event-detail-form";
@override
_EventDetailFormState createState() => _EventDetailFormState();
}
class _EventDetailFormState extends State<EventDetailForm> {
final myController = TextEditingController();
@override
void dispose() {
myController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Event Detail')),
body: Padding(
padding: const EdgeInsets.all(16),
child: TextField(
controller: myController,
)),
floatingActionButton: FloatingActionButton(
onPressed: () {
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Text(myController.text),
);
});
},
child: Icon(Icons.text_fields),
),
);
}
}
Unfortunately, I am not getting any error messages.不幸的是,我没有收到任何错误消息。 The cursor just blinks in the TextField and everything else loses function and I have to quit and restart.
cursor 只是在 TextField 中闪烁,其他所有内容都会丢失 function,我必须退出并重新启动。 I am not sure what else I should be considering.
我不确定我还应该考虑什么。 Does anyone have any ideas on what might be causing this?
有没有人对可能导致这种情况的原因有任何想法?
Simulator -> Device -> Erase All Content And Settings
works for me. Simulator -> Device -> Erase All Content And Settings
对我有用。
Had same problem when I upgraded Xcode to ios 13.1.当我将 Xcode 升级到 ios 13.1 时遇到了同样的问题。 I switched to a different simulator, and the problem went away.
我切换到另一个模拟器,问题就消失了。
This maybe late, but it happened to me too just today.这可能晚了,但今天也发生在我身上。 I also changed the
channel
to beta
but unfortunately did not work too.我也将
channel
更改为beta
,但不幸的是也没有用。 Apparently what worked for me is when I restarted the simulator after I put back the channel to stable
.显然,对我有用的是当我将频道放回
stable
后重新启动模拟器时。
I had the same bug, solved by switching to the beta channel of Flutter.我有同样的错误,通过切换到 Flutter 的 beta 通道解决。 In your terminal use
在您的终端使用
flutter channel beta
flutter upgrade
About channels you can read here https://github.com/flutter/flutter/wiki/Flutter-build-release-channels关于您可以在此处阅读的频道https://github.com/flutter/flutter/wiki/Flutter-build-release-channels
I did not change channel, a simple flutter upgrade
was enough to fix this problem.我没有改变频道,一个简单的
flutter upgrade
就足以解决这个问题。 I also closed Android Studio and all simulators and when I restarted, the problem was gone.我还关闭了 Android Studio 和所有模拟器,当我重新启动时,问题就消失了。
I think I am late to the party but the issue still exists in 2021.我想我迟到了,但这个问题在 2021 年仍然存在。
I tried all the solutions but couldn't fix it.我尝试了所有解决方案,但无法解决。 Whatever I was typing in TextField or TextFormField or autocomplete_textfield , the characters were not visible.
无论我在 TextField 或 TextFormField 或autocomplete_textfield中输入什么,这些字符都是不可见的。
I fixed it by opening the Widget as a showGeneralDialog()
instead of using Navigator.of(...)
.我通过将小部件打开为
showGeneralDialog()
而不是使用Navigator.of(...)
来修复它。 Here is the sample code.这是示例代码。
await showGeneralDialog(
barrierColor: AppStyle.primaryColor.withOpacity(0.3),
transitionBuilder: (context, a1, a2, widget) {
return Transform.scale(
scale: a1.value,
child: Opacity(opacity: a1.value, child: WidgetScreenToOpen()),
);
},
transitionDuration: Duration(milliseconds: 500),
barrierDismissible: true,
barrierLabel: 'Label',
context: context,
pageBuilder: (context, animation1, animation2) {
return Container();
}).then((result) {
return result;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.