[英]Physical KeyBoard Not working For TextFormField in desktop Flutter
最近我開始在桌面上制作管理面板並使用文本表單字段從用戶那里獲取輸入,但不幸的是,鍵盤無法在文本字段內寫入數據,我在谷歌上搜索並沒有找到任何解決方案,請有人幫忙我?
以下是我在項目中使用的一些文本字段:
Container(
width: 200,
margin: EdgeInsets.all(15),
child: TextFormField(
onChanged: (value) {
referalName.text = value;
},
validator: (value) {
if (value!.isEmpty) {
return 'Please Enter Referal Code';
}
return null;
},
controller: referalName,
style: TextStyle(
fontSize: 24,
color: Colors.blue,
fontWeight: FontWeight.w600,
),
decoration: InputDecoration(
focusColor: Colors.white,
//add prefix icon
prefixIcon: Icon(
Icons.person_outline_rounded,
color: Colors.grey,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Colors.blue, width: 1.0),
borderRadius: BorderRadius.circular(10.0),
),
fillColor: Colors.grey,
hintText: "Referal Name",
//make hint text
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 16,
fontFamily: "verdana_regular",
fontWeight: FontWeight.w400,
),
//create lable
labelText: 'Enter Referal Name',
//lable style
labelStyle: TextStyle(
color: Colors.grey,
fontSize: 16,
fontFamily: "verdana_regular",
fontWeight: FontWeight.w400,
),
),
),
),
我已經測試了你的代碼,它對我來說很好,除了一件事。 每次輸入字段中的文本更改時,您都會重置推薦 controller 的值。 這導致了意外錯誤。 嘗試刪除或注釋掉onChanged函數的代碼。
onChanged: (value) {
// referalName.text = value;
},
查看此鏈接以獲取更多信息:
https://api.flutter.dev/flutter/material/TextField/onChanged.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.