Upgrade follow latest

This commit is contained in:
Chandra Abdul Fattah
2023-03-07 22:11:56 +07:00
parent a4b2fe3179
commit 370c56908c
161 changed files with 1903 additions and 431 deletions

75
lib/src/country_code.dart Normal file
View File

@@ -0,0 +1,75 @@
import 'package:collection/collection.dart' show IterableExtension;
import 'package:flutter/cupertino.dart';
import 'country_codes.dart';
import 'country_localizations.dart';
mixin ToAlias {}
/// Country element. This is the element that contains all the information
class CountryCode {
/// the name of the country
String? name;
/// the flag of the country
final String? flagUri;
/// the country code (IT,AF..)
final String? code;
/// the dial code (+39,+93..)
final String? dialCode;
CountryCode({
this.name,
this.flagUri,
this.code,
this.dialCode,
});
@Deprecated('Use `fromCountryCode` instead.')
factory CountryCode.fromCode(String isoCode) {
return CountryCode.fromCountryCode(isoCode);
}
factory CountryCode.fromCountryCode(String countryCode) {
final Map<String, String>? jsonCode = codes.firstWhereOrNull(
(code) => code['code'] == countryCode,
);
return CountryCode.fromJson(jsonCode!);
}
factory CountryCode.fromDialCode(String dialCode) {
final Map<String, String>? jsonCode = codes.firstWhereOrNull(
(code) => code['dial_code'] == dialCode,
);
return CountryCode.fromJson(jsonCode!);
}
CountryCode localize(BuildContext context) {
return this
..name = CountryLocalizations.of(context)?.translate(code) ?? name;
}
factory CountryCode.fromJson(Map<String, dynamic> json) {
return CountryCode(
name: json['name'],
code: json['code'],
dialCode: json['dial_code'],
flagUri: 'flags/${json['code'].toLowerCase()}.png',
);
}
@override
String toString() => "$dialCode";
String toLongString() => "$dialCode ${toCountryStringOnly()}";
String toCountryStringOnly() {
return '$_cleanName';
}
String? get _cleanName {
return name?.replaceAll(RegExp(r'[[\]]'), '').split(',').first;
}
}