Skip to content

Commit

Permalink
Release 1.0, null-safety
Browse files Browse the repository at this point in the history
  • Loading branch information
denixport committed Mar 11, 2021
1 parent 19358aa commit f4bcc08
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 118 deletions.
18 changes: 12 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
## 0.1.0
Initial release

## 0.2.0-beta
## [1.0.0]
Stable, null-safe release
### Changed
- Requires Dart version >= 2.12
## [0.2.0-beta]
### Changed
- Refactored access to class values. Both ISO and user-assigned codes are
accessible through `values` list.
- added `index` getter to match enum behaviour
- added `symbol` getter

### Added
- `index` getter to match enum behaviour
- `symbol` getter

## [0.1.0]
Initial release
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ if (code == CountryCode.US) {
print(code.numeric);
}
```
[See more examples](https://github.com/denixport/dart.country/tree/master/example)

[See more examples][examples]

## Bugs and feature requests

Please file feature requests and bugs at the [issue tracker][tracker].

[examples]: https://github.com/denixport/dart.country/tree/master/example
[tracker]: https://github.com/denixport/dart.country/issues
7 changes: 3 additions & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ analyzer:
implicit-dynamic: false
errors:
dead_code: error
missing_required_param: warning
missing_return: warning
override_on_non_overriding_method: warning
missing_required_param: error
missing_return: error
todo: info
unused_element: error
unused_import: warning
unused_import: error
unused_local_variable: error

linter:
Expand Down
14 changes: 7 additions & 7 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ void main() {
print(CountryCode.US.symbol); // -> 🇺🇸

// The list of ISO-assigned codes are in CountryCode.values
var list = CountryCode.values.map<String>((c) => c.alpha2).join(", ");
var list = CountryCode.values.map<String>((c) => c.alpha2).join(', ');
print(list);

// You can statically access countries by alpha-2, alpha-3, or numeric code
// That's also helpful to get other ISO codes for known code
print(CountryCode.ofAlpha("US").alpha2); // -> US
print(CountryCode.ofAlpha("USA").alpha2); // -> US
print(CountryCode.ofAlpha('US').alpha2); // -> US
print(CountryCode.ofAlpha('USA').alpha2); // -> US
print(CountryCode.ofNumeric(840).alpha2); // -> US

// Always same values for the same country code is returned
print(identical(CountryCode.ofAlpha("US"), CountryCode.US)); // -> true
print(identical(CountryCode.ofAlpha('US'), CountryCode.US)); // -> true

// You can also parse alpha-2, alpha-3, or numeric code
print(CountryCode.parse("US").alpha2); // -> US
print(CountryCode.parse("USA").alpha2); // -> US
print(CountryCode.parse("840").alpha2); // -> US
print(CountryCode.parse('US').alpha2); // -> US
print(CountryCode.parse('USA').alpha2); // -> US
print(CountryCode.parse('840').alpha2); // -> US
}
25 changes: 12 additions & 13 deletions example/user_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ void main() {
CountryCode c1, c2, c3, c4, c5;

// Create values with custom codes (From ISO defined code range)
c1 = CountryCode.user(alpha2: "AA");
c1 = CountryCode.user(alpha2: 'AA');
print(c1.alpha2); // -> AA
print(c1.alpha3); // ->
print(c1.alpha3); // ->
print(c1.numeric); // -> 0

// Country values for the same code are equal, but not the same object
c1 = CountryCode.user(alpha3: "XAA");
c2 = CountryCode.user(alpha3: "XAA");
c1 = CountryCode.user(alpha3: 'XAA');
c2 = CountryCode.user(alpha3: 'XAA');
print(c1 == c2); // -> true
print(identical(c1, c2)); // -> false

// You need to assign country code using static method assign(),
// You need to assign country code using static method assign(),
// to be able to use parsing and static accessors for the code.
int index = CountryCode.assign(alpha3: "XAA", numeric: 901);
var index = CountryCode.assign(alpha3: 'XAA', numeric: 901);
print(index); // -> 0
print(CountryCode.userValues); // -> [Country.XXA]

c1 = CountryCode.userValues[index];
c2 = CountryCode.ofAlpha("XAA");
c2 = CountryCode.ofAlpha('XAA');
c3 = CountryCode.ofNumeric(901);
c4 = CountryCode.parse("XAA");
c5 = CountryCode.parse("901");
c4 = CountryCode.parse('XAA');
c5 = CountryCode.parse('901');

print(identical(c1, c2)); // -> true
print(identical(c2, c3)); // -> true
Expand All @@ -36,7 +36,6 @@ void main() {
CountryCode.unassignAll();
print(CountryCode.userValues.length); // -> 0

// Now you can not parse or get value for the code 'XAA'
print(CountryCode.tryParse("XAA")); // - null

// Now you can not parse or get value for the code 'XAA'
print(CountryCode.tryParse('XAA')); // - null
}
Loading

0 comments on commit f4bcc08

Please sign in to comment.