Skip to content

Commit

Permalink
fix: accept commas as decimal separators
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwahid committed Dec 1, 2023
1 parent 5f6df45 commit 967594e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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

0 comments on commit 967594e

Please sign in to comment.