perubahan denomuretor on pos sale
This commit is contained in:
@@ -55,6 +55,18 @@ class _AddPartyState extends State<AddParty> {
|
||||
final GlobalKey<FormState> _formKay = GlobalKey();
|
||||
FocusNode focusNode = FocusNode();
|
||||
|
||||
/// Normalizes Indonesian phone numbers to local format (0xx...)
|
||||
/// Handles: +6289..., 6289..., 0896.2792.1934, spaces, etc.
|
||||
String _normalizePhone(String input) {
|
||||
// Remove all non-digit characters (dots, spaces, dashes, +)
|
||||
String digits = input.replaceAll(RegExp(r'[^\d]'), '');
|
||||
// Strip country code: +62 or 62 at the start
|
||||
if (digits.startsWith('62')) {
|
||||
digits = '0' + digits.substring(2);
|
||||
}
|
||||
return digits;
|
||||
}
|
||||
|
||||
List<Country> _countries = [];
|
||||
Country? _selectedBillingCountry;
|
||||
Country? _selectedShippingCountry;
|
||||
@@ -152,11 +164,39 @@ class _AddPartyState extends State<AddParty> {
|
||||
TextFormField(
|
||||
controller: phoneController,
|
||||
keyboardType: TextInputType.phone,
|
||||
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||||
onChanged: (value) {
|
||||
final normalized = _normalizePhone(value);
|
||||
if (normalized != value) {
|
||||
phoneController.value = TextEditingValue(
|
||||
text: normalized,
|
||||
selection: TextSelection.collapsed(offset: normalized.length),
|
||||
);
|
||||
}
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return lang.S.of(context).pleaseEnterAValidPhoneNumber;
|
||||
}
|
||||
final digits = value.replaceAll(RegExp(r'[^\d]'), '');
|
||||
if (digits.length < 11 || digits.length > 13) {
|
||||
// Show popup after frame
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text('Invalid Phone Number'),
|
||||
content: Text('Phone number must be between 11 and 13 digits.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(),
|
||||
child: Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
return 'Invalid length';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
@@ -878,6 +918,28 @@ class _AddPartyState extends State<AddParty> {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate phone number length (11-13 digits)
|
||||
final phoneDigits = phoneController.text.replaceAll(RegExp(r'[^\d]'), '');
|
||||
if (phoneDigits.isNotEmpty && (phoneDigits.length < 11 || phoneDigits.length > 13)) {
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Invalid Number'),
|
||||
content: const Text(
|
||||
'Phone number must be between 11 and 13 digits.\n'
|
||||
'Example: 08123456789 (11 digits) or 081234567890 (12 digits).',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
num parseOrZero(String? input) {
|
||||
if (input == null || input.isEmpty) return 0;
|
||||
return num.tryParse(input) ?? 0;
|
||||
|
||||
Reference in New Issue
Block a user