fix : sale out of Province
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
extension XNumExtension on num? {
|
||||
String get toFormatted {
|
||||
String get separatedByComma {
|
||||
final formatter = NumberFormat('#,###', 'fa_IR');
|
||||
return this == null ? '':formatter.format(this);
|
||||
}
|
||||
|
||||
27
packages/core/lib/utils/separator_input_formatter.dart
Normal file
27
packages/core/lib/utils/separator_input_formatter.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class SeparatorInputFormatter extends TextInputFormatter {
|
||||
final NumberFormat _formatter;
|
||||
|
||||
SeparatorInputFormatter() : _formatter = NumberFormat('#,###');
|
||||
|
||||
@override
|
||||
TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
|
||||
if (newValue.text.isEmpty) {
|
||||
return newValue;
|
||||
}
|
||||
String tmpText = newValue.text;
|
||||
String cleanedText = tmpText.replaceAll(RegExp(r'\D'), '');
|
||||
int? number = int.tryParse(cleanedText);
|
||||
if (number == null) {
|
||||
return oldValue;
|
||||
}
|
||||
String formattedText = _formatter.format(number);
|
||||
int selectionIndex = formattedText.length;
|
||||
return TextEditingValue(
|
||||
text: formattedText,
|
||||
selection: TextSelection.collapsed(offset: selectionIndex),
|
||||
);
|
||||
}
|
||||
}
|
||||
11
packages/core/lib/utils/string_utils.dart
Normal file
11
packages/core/lib/utils/string_utils.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
extension XString on String {
|
||||
get separatedByComma {
|
||||
final formatter = NumberFormat('#,###');
|
||||
return formatter.format(this);
|
||||
}
|
||||
get clearComma{
|
||||
return replaceAll(RegExp(r'\D'), '');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user