【发布时间】:2020-08-13 00:18:14
【问题描述】:
我有一个 TextField 小部件可以在列表中添加玩家。但是我希望键盘在添加玩家时保持焦点,并且在提交时,我的键盘一直失去焦点..有什么想法吗?
这是我的 TextField 小部件:
TextField(
textCapitalization: TextCapitalization.words,
onChanged: (val) => playerName = val.trim(),
onSubmitted: (val) {
if (playerName != null && playerName != '') {
Provider.of<PlayerProvider>(context, listen: false).addPlayer(playerName);
HapticFeedback.lightImpact();
}
},
maxLength: 19,
autocorrect: false,
decoration: new InputDecoration(
counterText: "",
border: new OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: const BorderRadius.all(
const Radius.circular(30.0),
),
),
filled: true,
contentPadding: EdgeInsets.symmetric(vertical: 0, horizontal: 20),
hintStyle: GoogleFonts.rubik(color: Colors.grey[500], fontWeight: FontWeight.bold),
hintText: AppLocalizations.of(context).translate('player_selection_page_hint'),
fillColor: Colors.white),
)
顺便说一句,autofocus: true 可以工作,但它有点使键盘失焦并立即将焦点返回……所以看起来不太好。所以如果你有其他想法,请。
【问题讨论】:
标签: flutter keyboard textfield