我正在尝试检测用户何时按下退格键。我有一个 Package 在RawKeyboardListener中的TextField,它在Android上可以正常工作,但在iOS上似乎不起作用。我错过了什么?
在我的代码中,我试图检查检测到的按键是否等于logicalkeyboard.backspace或physicalkeyboard.backspace。我注意到iOS上没有检测到按键,所以看起来问题似乎是RawKeyboardListener无法检测到按键?
RawKeyboardListener(
focusNode: FocusNode(),
onKey: (key) {
setState(() {
print('stuff');
//LogicalKeyboardKey.backspace
if (Platform.isIOS) {
if (key.logicalKey == LogicalKeyboardKey.backspace) {
print('this is working');
}
}
if (key.logicalKey == PhysicalKeyboardKey.backspace) {
detectDeleteKey = true;
// birthDateController.text.replaceRange(
// birthDateController.text.length - 1, null, '');
}
else {
detectDeleteKey = false;
}
});
},
child: RegistrationFieldRow(
leftTextCapitalization: TextCapitalization.none,
leftTextInputType: TextInputType.number,
leftController: birthDateController,
leftOnChanged: (String value) {
setState(() {
birthDateResult = birthDateRuleValidation(
birthDateController,
10,
value,
{
'numbersOnly': 'birthDateNumbersOnlyChar',
'charValidationList': 'birthDateChars',
'maxCharCount': 'birthDateMaxCharCount',
'charCount': 'birthDateCharCount',
'ageCheck': 'birthDateAgeVerification'
},
detectDeleteKey)!;
if (birthDateResult != '') {
birthDateRuleCheck = true;
}
else {
birthDateRuleCheck = false;
}
});
},
leftFieldPrefixIcon: const Icon(FontAwesomeIcons.calendarDay,
size: 15.0,
color: ePrimaryAccentColor,),
leftFieldHintText: 'Birth Date',
rightController: zipCodeController,
rightTextCapitalization: TextCapitalization.none,
rightTextInputType: TextInputType.number,
rightOnChanged: (String value) async {
locationDataAutoFill();
},
rightFieldPrefixIcon: const Icon(FontAwesomeIcons.globe,
size: 15.0,
color: ePrimaryAccentColor,),
rightFieldHintText: 'Zip Code',
),
),
1条答案
按热度按时间wpx232ag1#
尝试
事件.逻辑键==逻辑键盘键.退格键〈〈android
事件.物理键==物理键盘键.退格键〈〈ios,android