You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The PhoneInputFormatter has a bug where it incorrectly converts the Brazilian area code 83 (Paraíba state) to 73 (Bahia state) during phone number formatting.
Steps to Reproduce
Create a PhoneInputFormatter with Brazilian settings:
final formatter =PhoneInputFormatter(
allowEndlessPhone:false,
defaultCountryCode:'BR',
);
Try to format a phone number starting with area code 83:
final result = formatter.formatEditUpdate(
TextEditingValue(),
TextEditingValue(text:'83987654321'),
);
Observe the result
Expected Behavior
Input: 83987654321
Expected output: (83) 98765-4321
Actual Behavior
Input: 83987654321
Actual output: (73) 98765-4321 ❌
The area code is incorrectly changed from 83 to 73.
bug.mp4
Impact
This affects users from Paraíba state (Brazil) who cannot correctly input their phone numbers. Area code 83 is a valid Brazilian area code assigned to Paraíba state by ANATEL (Brazilian telecommunications agency).
Environment
Package: flutter_multi_formatter
Versions tested: 2.10.0, 2.12.0, 2.13.10 (bug exists in all tested versions)
Flutter: 3.24.3
Dart: 3.5.3
Platform: iOS/Android
Additional Context
Area code 83 is officially assigned to Paraíba state, Brazil
Area code 73 is assigned to Bahia state, Brazil
This appears to be a mapping issue within the library's phone formatting logic
The bug occurs both during step-by-step typing and when formatting complete numbers
Workaround
We've implemented a temporary wrapper that detects and fixes this specific case:
classCustomPhoneInputFormatterextendsTextInputFormatter {
finalPhoneInputFormatter _baseFormatter;
// ... constructor@overrideTextEditingValueformatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
final baseResult = _baseFormatter.formatEditUpdate(oldValue, newValue);
// Fix the specific bug: DDD 83 being changed to 73if (_shouldFixDDD83(newValue.text, baseResult.text)) {
final correctedText = baseResult.text.replaceFirst('(73', '(83');
returnTextEditingValue(
text: correctedText,
selection:TextSelection.collapsed(offset: correctedText.length),
);
}
return baseResult;
}
bool_shouldFixDDD83(String originalText, String formattedText) {
final original = originalText.replaceAll(RegExp(r'[^\d]'), '');
final formatted = formattedText.replaceAll(RegExp(r'[^\d]'), '');
return original.startsWith('83') && formatted.startsWith('73');
}
}
Test Case
voidmain() {
test('PhoneInputFormatter should preserve area code 83', () {
final formatter =PhoneInputFormatter(
allowEndlessPhone:false,
defaultCountryCode:'BR',
);
final result = formatter.formatEditUpdate(
TextEditingValue(),
TextEditingValue(text:'83987654321'),
);
expect(result.text, contains('83')); // Should contain 83expect(result.text, isNot(contains('73'))); // Should NOT contain 73
});
}
Would appreciate a fix for this issue as it affects Brazilian users from Paraíba state.
Bug Description
The
PhoneInputFormatterhas a bug where it incorrectly converts the Brazilian area code 83 (Paraíba state) to 73 (Bahia state) during phone number formatting.Steps to Reproduce
Create a
PhoneInputFormatterwith Brazilian settings:Try to format a phone number starting with area code 83:
Observe the result
Expected Behavior
83987654321(83) 98765-4321Actual Behavior
83987654321(73) 98765-4321❌The area code is incorrectly changed from 83 to 73.
bug.mp4
Impact
This affects users from Paraíba state (Brazil) who cannot correctly input their phone numbers. Area code 83 is a valid Brazilian area code assigned to Paraíba state by ANATEL (Brazilian telecommunications agency).
Environment
flutter_multi_formatter2.10.0,2.12.0,2.13.10(bug exists in all tested versions)3.24.33.5.3Additional Context
Workaround
We've implemented a temporary wrapper that detects and fixes this specific case:
Test Case
Would appreciate a fix for this issue as it affects Brazilian users from Paraíba state.