1.3.0
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import 'package:country_code_picker/country_codes.dart';
|
||||
import 'package:country_code_picker/country_localizations.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
mixin ToAlias {}
|
||||
|
||||
@deprecated
|
||||
@@ -9,20 +13,53 @@ class CountryCode {
|
||||
String name;
|
||||
|
||||
/// the flag of the country
|
||||
String flagUri;
|
||||
final String flagUri;
|
||||
|
||||
/// the country code (IT,AF..)
|
||||
String code;
|
||||
final String code;
|
||||
|
||||
/// the dial code (+39,+93..)
|
||||
String dialCode;
|
||||
final String dialCode;
|
||||
|
||||
CountryCode({this.name, this.flagUri, this.code, this.dialCode});
|
||||
CountryCode({
|
||||
this.name,
|
||||
this.flagUri,
|
||||
this.code,
|
||||
this.dialCode,
|
||||
});
|
||||
|
||||
factory CountryCode.fromCode(String isoCode) {
|
||||
final Map<String, String> jsonCode = codes.firstWhere(
|
||||
(code) => code['code'] == isoCode,
|
||||
orElse: () => null,
|
||||
);
|
||||
|
||||
if (jsonCode == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return CountryCode.fromJson(jsonCode);
|
||||
}
|
||||
|
||||
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 $name";
|
||||
String toLongString([BuildContext context]) =>
|
||||
"$dialCode ${toCountryStringOnly(context)}";
|
||||
|
||||
String toCountryStringOnly() => '$name';
|
||||
String toCountryStringOnly([BuildContext context]) {
|
||||
if (context != null) {
|
||||
return CountryLocalizations.of(context)?.translate(code) ?? name;
|
||||
}
|
||||
return '$name';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user