Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions demo/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ class _MyHomePageState extends State<MyHomePage> {
format: NsnFormat.international))
: const Text('-'),
),
ListTile(
title: const Text('Formatted with country code'),
trailing: phoneNumber != null
? Text(
phoneNumber.format(
format: NsnFormat.international,
),
)
: const Text('-'),
),
ListTile(
title: const Text('Iso code'),
trailing: phoneNumber != null
Expand Down
6 changes: 4 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ void main(List<String> arguments) {
print('');
print('Formatting:');
final phoneNumber =
PhoneNumber.parse('2025550119', destinationCountry: IsoCode.US);
PhoneNumber.parse('+12025550119', destinationCountry: IsoCode.US);
final formattedNsn = phoneNumber.formatNsn();
print('formatted: $formattedNsn'); // (202) 555-0119
print('formatted nsn: $formattedNsn'); // (202) 555-0119
print('international: ${phoneNumber.international}');
final formatted = phoneNumber.format();
print('formatted with country code: $formatted'); // +1 (202) 555-0119
// Ranges
print('');
print('Ranges:');
Expand Down
2 changes: 2 additions & 0 deletions lib/src/formatting/phone_number_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class PhoneNumberFormatter {
pattern: formatingRule.pattern,
transformRule: transformRule,
);

formatted = _removeMissingDigits(formatted, missingDigits);

return formatted;
}

Expand Down
4 changes: 4 additions & 0 deletions lib/src/phone_number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class PhoneNumber {
String formatNsn({IsoCode? isoCode, NsnFormat format = NsnFormat.national}) =>
PhoneNumberFormatter.formatNsn(nsn, isoCode ?? this.isoCode, format);

String format({IsoCode? isoCode, NsnFormat format = NsnFormat.national}) {
return '+$countryCode ${formatNsn(isoCode: isoCode, format: format)}';
}

@Deprecated('Use [formatNsn] instead')
String getFormattedNsn({IsoCode? isoCode}) => formatNsn(isoCode: isoCode);

Expand Down