Skip to content

Commit 294fc3a

Browse files
committed
💡 Add code documentation
1 parent 9761925 commit 294fc3a

File tree

1 file changed

+136
-2
lines changed

1 file changed

+136
-2
lines changed

lib/country_provider.dart

Lines changed: 136 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ class CountryProvider {
1414
static Client _client = Client();
1515
static String _baseUrl = Constants.restCounteriesBaseUri;
1616

17-
/// Get all countries.
17+
/// Get information about countries
18+
/// ```dart
19+
/// Future<List<Country>> getCountry(String name){
20+
/// try{
21+
/// List<Country> countries = await CountryProvider.getAllCountries();
22+
/// return result;
23+
/// } catch(error) {
24+
/// print(error);
25+
/// }
26+
/// }
27+
/// ``
1828
static Future<List<Country>> getAllCountries({CountryFilter filter}) async {
1929
var uri =
2030
"$_baseUrl" + Constants.allCountrySiffixUri + filter.toFormattedUri;
@@ -31,6 +41,21 @@ class CountryProvider {
3141
"No country found. Please check if https://restcountries.eu is avialable.");
3242
}
3343

44+
/// Search by country name
45+
///
46+
/// You can pass incomplete country name
47+
/// ```dart
48+
/// Future<List<Country>> getCountry(String name){
49+
/// try{
50+
/// List<Country> result = await CountryProvider.getCountriesByName("Ameri")
51+
/// return result;
52+
/// } catch(error) {
53+
/// print(error);
54+
/// return null;
55+
/// }
56+
/// }
57+
/// ```
58+
3459
static Future<List<Country>> getCountriesByName(String name,
3560
{CountryFilter filter}) async {
3661
if (name != null && name.isNotEmpty) {
@@ -54,6 +79,18 @@ class CountryProvider {
5479
}
5580
}
5681

82+
/// Search by country full name: `India`, `Cambodia`, `Canada`
83+
/// ```dart
84+
/// Future<Country> getCountry(String name){
85+
/// try{
86+
/// Country result = await CountryProvider.getCountryByFullname("India")?.first;
87+
/// return result;
88+
/// } catch(error) {
89+
/// print(error);
90+
/// return null;
91+
/// }
92+
/// }
93+
/// ```
5794
static Future<Country> getCountryByFullname(String name,
5895
{CountryFilter filter}) async {
5996
if (name != null && name.isNotEmpty) {
@@ -80,6 +117,18 @@ class CountryProvider {
80117
}
81118
}
82119

120+
/// Search by list of ISO 3166-1 2-letter or 3-letter country codes: `Ind`, `Col`, `ru`
121+
/// ```dart
122+
/// Future<Country> getCountry(String name){
123+
/// try{
124+
/// Country result = await CountryProvider.getCountryByCode("Ind")?.first;
125+
/// return result;
126+
/// } catch(error) {
127+
/// print(error);
128+
/// return null;
129+
/// }
130+
/// }
131+
/// ```
83132
static Future<Country> getCountryByCode(String code,
84133
{CountryFilter filter}) async {
85134
if (code != null && code.isNotEmpty) {
@@ -99,6 +148,18 @@ class CountryProvider {
99148
}
100149
}
101150

151+
/// Search by list of ISO 3166-1 2-letter or 3-letter country codes: `["Ind", "col", "ru"]`
152+
/// ```dart
153+
/// Future<List<Country>> getCountry(String name){
154+
/// try{
155+
/// List<Country> result = CountryProvider.getCountriesByListOfCodes(["Ind", "col", "ru"]);
156+
/// return result;
157+
/// } catch(error) {
158+
/// print(error);
159+
/// return null;
160+
/// }
161+
/// }
162+
/// ```
102163
static Future<List<Country>> getCountriesByListOfCodes(List<String> codes,
103164
{CountryFilter filter}) async {
104165
if (codes != null && codes.isNotEmpty) {
@@ -124,6 +185,18 @@ class CountryProvider {
124185
}
125186
}
126187

188+
/// Search by ISO 4217 currency code: `Inr`, `Aud`, `Bmd`, `Usd`, `Eur`, `Gbp`
189+
/// ```dart
190+
/// Future<List<Country>> getCountry(String name){
191+
/// try{
192+
/// List<Country> result = await CountryProvider.getCountryByCurrencyCode("Inr")
193+
/// return result;
194+
/// } catch(error) {
195+
/// print(error);
196+
/// return null;
197+
/// }
198+
/// }
199+
/// ```
127200
static Future<List<Country>> getCountryByCurrencyCode(String currencyCode,
128201
{CountryFilter filter}) async {
129202
if (currencyCode != null && currencyCode.isNotEmpty) {
@@ -146,6 +219,18 @@ class CountryProvider {
146219
}
147220
}
148221

222+
/// Search by ISO 639-1 language code: `jpn`, `en`, `hin`, `ru`,
223+
/// ```dart
224+
/// Future<List<Country>> getCountry(String name){
225+
/// try{
226+
/// List<Country> result = await CountryProvider.getCountriesByLanguageCode(["Hin","en",]);
227+
/// return result;
228+
/// } catch(error) {
229+
/// print(error);
230+
/// return null;
231+
/// }
232+
/// }
233+
/// ```
149234
static Future<List<Country>> getCountriesByLanguageCode(
150235
List<String> languageCode,
151236
{CountryFilter filter}) async {
@@ -169,14 +254,26 @@ class CountryProvider {
169254
}
170255
}
171256

257+
/// Search by capital city: `Tokyo`, `Rome`, `Bankok`, `London`, `Kampla`
258+
/// ```dart
259+
/// Future<List<Country>> getCountry(String name){
260+
/// try{
261+
/// List<Country> result = await CountryProvider.getCountryByCapitalCity("Delhi");
262+
/// return result;
263+
/// } catch(error) {
264+
/// print(error);
265+
/// return null;
266+
/// }
267+
/// }
268+
/// ```
172269
static Future<List<Country>> getCountryByCapitalCity(String capitalName,
173270
{CountryFilter filter}) async {
174271
if (capitalName != null && capitalName.isNotEmpty) {
175272
final uri = "$_baseUrl" +
176273
Constants.countriesByCapitalCity +
177274
capitalName +
178275
filter.toFormattedUri;
179-
276+
180277
print(uri);
181278
var response = await _client.get(uri);
182279

@@ -192,6 +289,18 @@ class CountryProvider {
192289
}
193290
}
194291

292+
/// Search by calling code: `91`, `61`, `55`, `855`, `81`
293+
/// ```dart
294+
/// Future<List<Country>> getCountry(String name){
295+
/// try{
296+
/// List<Country> result = await CountryProvider.getCountryByCallingCode(91);
297+
/// return result;
298+
/// } catch(error) {
299+
/// print(error);
300+
/// return null;
301+
/// }
302+
/// }
303+
/// ```
195304
static Future<List<Country>> getCountryByCallingCode(int callingCode,
196305
{CountryFilter filter}) async {
197306
if (callingCode != null && callingCode > 0) {
@@ -214,6 +323,18 @@ class CountryProvider {
214323
}
215324
}
216325

326+
/// Search by continent: `Africa`, `Americas`, `Asia`, `Europe`, `Oceania`.
327+
/// ```dart
328+
/// Future<List<Country>> getCountry(String name){
329+
/// try{
330+
/// List<Country> result = await CountryProvider.getcountryByRegionalBloc("Asia");
331+
/// return result;
332+
/// } catch(error) {
333+
/// print(error);
334+
/// return null;
335+
/// }
336+
/// }
337+
/// ```
217338
static Future<List<Country>> getCountriesByContinent(String continentName,
218339
{CountryFilter filter}) async {
219340
if (continentName != null && continentName.isNotEmpty) {
@@ -236,6 +357,19 @@ class CountryProvider {
236357
}
237358
}
238359

360+
361+
/// Search by regional bloc: `EU`, `EFTA`, `CARICOM`, `AU`, `USAN`, `EEU`, `AL`, `ASEAN` , `CAIS`, `CEFTA` , `NAFTA` , `SAARC`.
362+
/// ```dart
363+
/// Future<List<Country>> getCountry(String name){
364+
/// try{
365+
/// List<Country> result = await CountryProvider.getCountriesByContinent("ASEAN");
366+
/// return result;
367+
/// } catch(error) {
368+
/// print(error);
369+
/// return null;
370+
/// }
371+
/// }
372+
/// ```
239373
static Future<List<Country>> getcountryByRegionalBloc(String regiaonBlocName,
240374
{CountryFilter filter}) async {
241375
if (regiaonBlocName != null && regiaonBlocName.isNotEmpty) {

0 commit comments

Comments
 (0)