我正在研究 Flutter,基于搜索参数调用 API。
我所做的是:
问题:当我使用 back press 完成搜索后隐藏键盘时,它再次请求获取数据。
你可以查看视频以获得更好的解释:
这是我的代码:
getTextInputField() {
return Flexible(
fit: FlexFit.tight,
flex: 1,
child: TextFormField(
controller: _text,
decoration: new InputDecoration(
labelText: "Enter Area for Pincode",
fillColor: Colors.white,
errorText: _validateAgain ? 'This should not be empty!' : null,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(15.0),
borderSide: new BorderSide(),
),
//fillColor: Colors.green
),
validator: (val) {
if (val.length == 0) {
return "This shouldn't be empty!";
} …Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我在“controller: urlController”这一行上收到错误
var url;
final urlController = TextEditingController();
@override
void dispose() {
urlController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: const Color(0xff16352A),
title: const Text(
'Downloader',
style: TextStyle(color: Color(0xffEDAB24)),
),
),
body: Container(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(height: 50.0),
const TextField(
controller: urlController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Paste URL',
),
),
const SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
TextButton(
onPressed: () {},
child: const Text(
'Download',
style: …Run Code Online (Sandbox Code Playgroud) 我正在为 Windows 构建一个 Flutter 应用程序。\n我有一个 TextField,如果我运行该应用程序并想要通过按住 Shift Left 或 Shift Right 和一个字母来插入大写字符,我会收到以下错误:
\nThe following assertion was thrown during a platform message callback: \nA KeyRepeatEvent is dispatched, but the state shows that the physical key is not pressed. If this occurs in real application, please report this bug to Flutter. If this occurs in unit tests, please ensure that simulated events follow Flutter's event model as documented in `HardwareKeyboard`. This was the event: KeyRepeatEvent#d843e(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName: "Shift Left"), logicalKey: …Run Code Online (Sandbox Code Playgroud) Flutter 表单保存错误有一个 formKey 但我仍然收到错误
这是我的代码
class _TextFormFieldsState extends State<TextFormFields> {
String _name = "";
final formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Theme(
data: Theme.of(context).copyWith(
primaryColor: Colors.red,
accentColor: Colors.purpleAccent,
errorColor: Colors.black
),
child: Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.save),
),
appBar: AppBar(
title: Text("Text Form Field"),
),
body: Padding(
padding: EdgeInsets.all(20),
child: Form(
key: formKey,
autovalidateMode: AutovalidateMode.always,
child: ListView(
children: [
TextFormField(
decoration: InputDecoration(
prefixIcon: Icon(Icons.account_circle),
hintText: "Your Name",
labelText: "FullName",
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10)),
), …Run Code Online (Sandbox Code Playgroud)