Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: accept commas as decimal separators #116

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/screens/home/send/send_amount_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,22 @@ class _SendAmountSheetState extends State<SendAmountSheet> {
controller: _amountController,
focusNode: _amountFocus,
keyboardType: const TextInputType.numberWithOptions(decimal: true),
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'^\.?\d*(?<!\.)\.?\d*'))],
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'^(\d+)?([.,](\d+)?)?'))],
style: TextStyle(fontFamily: AppThemes.fonts.gilroyBold, fontSize: 25),
textAlign: TextAlign.center,
decoration: const InputDecoration(
border: InputBorder.none,
),
onChanged: (val){
if (val.contains(",")){
val = val.replaceAll(",", ".");
_amountController.text = val;
_amountController.value = _amountController.value.copyWith(
selection:
TextSelection(baseOffset: val.length, extentOffset: val.length),
composing: TextRange.empty,
);
}
_validateAmountInput(val);
},
),
Expand Down
11 changes: 10 additions & 1 deletion lib/screens/home/swap/swap_main_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class _SwapMainSheetState extends State<SwapMainSheet> {
controller: _baseController,
focusNode: _baseFocusNode,
keyboardType: const TextInputType.numberWithOptions(decimal: true),
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'^\.?\d*(?<!\.)\.?\d*'))],
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'^(\d+)?([.,](\d+)?)?'))],
style: TextStyle(fontFamily: AppThemes.fonts.gilroyBold, fontSize: 25),
textAlign: TextAlign.center,
decoration: InputDecoration(
Expand All @@ -210,6 +210,15 @@ class _SwapMainSheetState extends State<SwapMainSheet> {
)
),
onChanged: (val){
if (val.contains(",")){
val = val.replaceAll(",", ".");
_baseController.text = val;
_baseController.value = _baseController.value.copyWith(
selection:
TextSelection(baseOffset: val.length, extentOffset: val.length),
composing: TextRange.empty,
);
}
_validateAmountInput(val);
},
),
Expand Down