我有一個 textField,我只想在上面接受大寫字母,所以如果我輸入“asd”,它必須在欄位中轉換為“ASD”。
我已經嘗試過 TextCapitalization.character 但它會激活大寫鎖定,如果我關閉它,我的下一個字母將以小寫顯示。我不想在任何情況下都接受小寫字母。
有沒有辦法做到這一點?
編輯 - 我做了什么
TextField(
textCapitalization: TextCapitalization.characters,
)
uj5u.com熱心網友回復:
您可以TextInputFormatter在內部使用自定義TextField( inputFormatters: [UppercaseInputFormatter()], ...)
class UppercaseInputFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
return newValue.copyWith(text: newValue.text.toUpperCase());
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/360799.html
