Pull to refresh implemented

pull/213/head
haroon amjad 2 days ago
parent 71030c0fe9
commit 991f9c7a9b

@ -270,7 +270,7 @@ class _RechargeWalletPageState extends State<RechargeWalletPage> {
isCloseButtonVisible: true,
);
} else {
habibWalletVM.setWalletRechargeAmount(num.parse(amountTextController.text));
habibWalletVM.setWalletRechargeAmount(num.parse(amountTextController.text.replaceAll(',', '')));
habibWalletVM.setNotesText(notesTextController.text);
// habibWalletVM.setDepositorDetails(appState.getAuthenticatedUser()!.patientId.toString(), "${appState.getAuthenticatedUser()!.firstName} ${appState.getAuthenticatedUser()!.lastName}",
// appState.getAuthenticatedUser()!.mobileNumber!);

File diff suppressed because it is too large Load Diff

@ -304,7 +304,7 @@ class TextInputWidget extends StatelessWidget {
hintLocales: const [Locale('en', 'US')],
enabled: isEnable,
scrollPadding: EdgeInsets.zero,
keyboardType: isMultiline ? TextInputType.multiline : keyboardType,
keyboardType: isMultiline ? TextInputType.multiline : (isWalletAmountInput! ? const TextInputType.numberWithOptions(decimal: true) : keyboardType),
controller: controller,
readOnly: isReadOnly,
textAlignVertical: TextAlignVertical.top,
@ -315,7 +315,12 @@ class TextInputWidget extends StatelessWidget {
autofocus: autoFocus,
textInputAction: TextInputAction.done,
cursorHeight: isWalletAmountInput! ? 40.h : 20.h,
maxLength: isWalletAmountInput! ? 6 : 100,
maxLength: isWalletAmountInput! ? 7 : 100,
inputFormatters: isWalletAmountInput!
? [
_ThousandSeparatorInputFormatter(),
]
: null,
onTapOutside: (event) {
FocusManager.instance.primaryFocus?.unfocus();
},
@ -407,3 +412,63 @@ class TextInputWidget extends StatelessWidget {
);
}
}
class _ThousandSeparatorInputFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue,
TextEditingValue newValue,
) {
// Remove all commas to get the raw number
String newText = newValue.text.replaceAll(',', '');
// Allow only digits and one decimal point
if (newText.isNotEmpty && !RegExp(r'^\d*\.?\d{0,2}$').hasMatch(newText)) {
return oldValue;
}
// Split into integer and decimal parts
String integerPart;
String decimalPart = '';
if (newText.contains('.')) {
final parts = newText.split('.');
integerPart = parts[0];
decimalPart = '.${parts[1]}';
} else {
integerPart = newText;
}
// Add thousand separators to the integer part
if (integerPart.isNotEmpty) {
final buffer = StringBuffer();
int count = 0;
for (int i = integerPart.length - 1; i >= 0; i--) {
buffer.write(integerPart[i]);
count++;
if (count == 3 && i > 0) {
buffer.write(',');
count = 0;
}
}
integerPart = buffer.toString().split('').reversed.join();
}
final formatted = '$integerPart$decimalPart';
// Calculate new cursor position
int cursorOffset = newValue.selection.baseOffset;
// Count commas before cursor in the new formatted string
int commasInNew = ','.allMatches(formatted.substring(0, cursorOffset.clamp(0, formatted.length))).length;
// Count commas before cursor in the old value
int commasInOld = ','.allMatches(oldValue.text.substring(0, oldValue.selection.baseOffset.clamp(0, oldValue.text.length))).length;
int newCursorPos = cursorOffset + (commasInNew - commasInOld);
newCursorPos = newCursorPos.clamp(0, formatted.length);
return TextEditingValue(
text: formatted,
selection: TextSelection.collapsed(offset: newCursorPos),
);
}
}

Loading…
Cancel
Save