Skip to content

Commit

Permalink
fix: allow numeric value input for amount
Browse files Browse the repository at this point in the history
 from h4h13#411
  • Loading branch information
SahSantoshh committed Dec 29, 2023
1 parent 6160c8d commit 6ec67ea
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:paisa/core/common.dart';
import 'package:paisa/features/transaction/presentation/bloc/transaction_bloc.dart';
import 'package:paisa/core/widgets/paisa_widget.dart';
import 'package:paisa/features/transaction/presentation/bloc/transaction_bloc.dart';

class TransactionAmountWidget extends StatelessWidget {
const TransactionAmountWidget({
Expand All @@ -20,10 +21,21 @@ class TransactionAmountWidget extends StatelessWidget {
child: PaisaTextFormField(
controller: controller,
hintText: context.loc.amount,
keyboardType: TextInputType.text,
keyboardType: const TextInputType.numberWithOptions(),
maxLength: 13,
maxLines: 1,
counterText: '',
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r"[0-9.]")),
TextInputFormatter.withFunction((oldValue, newValue) {
final text = newValue.text;
return text.isEmpty
? newValue
: double.tryParse(text) == null
? oldValue
: newValue;
}),
],
onChanged: (value) {
double? amount = double.tryParse(value);
BlocProvider.of<TransactionBloc>(context).transactionAmount = amount;
Expand Down

0 comments on commit 6ec67ea

Please sign in to comment.