gpt4 book ai didi

flutter 文本字段 "Changing the content within the the composing region may cause the input"

转载 作者:行者123 更新时间:2023-12-05 03:40:32 24 4
gpt4 key购买 nike

我创建了一个新的 Flutter 应用程序,并尝试使用我之前在多个应用程序中使用过的流程在 TextField 小部件中设置初始值。每当我在字段中编辑内容时,Android Studio 运行窗口都会显示:

W/TextInputPlugin(18696): Changing the content within the the composing region may cause the input method to behave strangely, and is therefore discouraged. See https://github.com/flutter/flutter/issues/78827 for more details
W/IInputConnectionWrapper(18696): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(18696): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(18696): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper(18696): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(18696): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(18696): endBatchEdit on inactive InputConnection

当我查看引用的链接时,我没有看到任何描述解决方案的内容。

为了测试这个,我制作了一个新的、干净的应用程序,只有一个 Text 小部件和 TextEdit 小部件,但我仍然遇到同样的问题。除了设置默认值外,我什么也没做。最终我想捕获对输入字段的更改并将值写入本地存储,但我想我会先修复这个输入错误。

这是我的测试应用程序的代码:

import 'package:flutter/material.dart';

const appName = 'TextField Test';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: appName,
debugShowCheckedModeBanner: false,
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
home: HomePage(title: appName),
);
}
}

class HomePage extends StatefulWidget {
HomePage({Key? key, required this.title}) : super(key: key);
final String title;

@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
late TextEditingController textEditingController;
String _inputValue = '';

@override
void initState() {
super.initState();
textEditingController = TextEditingController(text: _inputValue);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Padding(
padding: const EdgeInsets.all(10.0),
child:
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text('This is some content in a Text widget'),
SizedBox(height: 10),
TextField(
autofocus: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Enter some text here'),
controller: textEditingController,
),
]),
));
}
}

有人可以告诉我我做错了什么吗?

当我向 Controller 添加一个监听器时,我注意到它会为我键入的每个字符触发多次:

I/flutter (18696): Listener fired the e
I/flutter (18696): Listener fired the e
I/flutter (18696): Listener fired the en
I/flutter (18696): Listener fired the en

这是监听器代码:

 @override
void initState() {
super.initState();
textEditingController = TextEditingController(text: _inputValue);
textEditingController.addListener(() {
print('Listener fired ${textEditingController.text}');
});
}

最佳答案

这只是一个警告。 İ 如果您不使用计算机键盘而感到困扰,请在模拟器上使用虚拟键盘。

关于 flutter 文本字段 "Changing the content within the the composing region may cause the input",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68075005/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com