Skip to content

Commit

Permalink
V2.0.1
Browse files Browse the repository at this point in the history
Merge pull request #15 from Daniel-Ioannou/v2.0.1
  • Loading branch information
Daniel-Ioannou committed Mar 12, 2021
2 parents 13aca1c + b4c3141 commit 6a3de83
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 13 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [2.0.1] - 12 Mar 2021

* Add `favorite` option.
- Can be used to to show the favorite currencies at the top of the list.
- It takes a list of currency code.
```Dart
showCurrencyPicker(
context: context,
onSelect: (Currency currency) {
print('Select currency: ${currency.name}');
},
favorite: <String> ['EUR', 'GBP', 'USD'],
);
```
## [2.0.0] - 05 Mar 2021

* Migrated to null safety
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A flutter package to select a currency from a list of currencies.
Add the package to your pubspec.yaml:

```yaml
currency_picker: ^2.0.0
currency_picker: ^2.0.1
```

In your dart file, import the library:
Expand All @@ -38,7 +38,7 @@ showCurrencyPicker(
* `searchHint`: Option to customize hint of the search TextField (optional).
* `showCurrencyName`: Option to show/hide the currency name, default value `true` (optional).
* `showCurrencyCode`: Option to show/hide the currency code, default value `true` (optional).
* `currencyFilter`: Can be used to uses filter the Currency list (optional).
* `currencyFilter`: Can be used to filter the Currency list (optional).
```Dart
showCurrencyPicker(
context: context,
Expand All @@ -48,6 +48,7 @@ showCurrencyPicker(
currencyFilter: <String>['EUR', 'GBP', 'USD', 'AUD', 'CAD', 'JPY', 'HKD', 'CHF', 'SEK', 'ILS'],
);
```
* `favorite`: Can be used to show the favorite currencies at the top of the list (optional).

## Contributions
Contributions of any kind are more than welcome! Feel free to fork and improve currency_picker in any way you want, make a pull request, or open an issue.
5 changes: 3 additions & 2 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A flutter package to select a currency from a list of currencies.
Add the package to your pubspec.yaml:

```yaml
currency_picker: ^2.0.0
currency_picker: ^2.0.1
```

In your dart file, import the library:
Expand All @@ -38,7 +38,7 @@ showCurrencyPicker(
* `searchHint`: Option to customize hint of the search TextField (optional).
* `showCurrencyName`: Option to show/hide the currency name, default value `true` (optional).
* `showCurrencyCode`: Option to show/hide the currency code, default value `true` (optional).
* `currencyFilter`: Can be used to uses filter the Currency list (optional).
* `currencyFilter`: Can be used to filter the Currency list (optional).
```Dart
showCurrencyPicker(
context: context,
Expand All @@ -48,6 +48,7 @@ showCurrencyPicker(
currencyFilter: <String>['EUR', 'GBP', 'USD', 'AUD', 'CAD', 'JPY', 'HKD', 'CHF', 'SEK', 'ILS'],
);
```
* `favorite`: Can be used to show the favorite currencies at the top of the list (optional).

## Contributions
Contributions of any kind are more than welcome! Feel free to fork and improve currency_picker in any way you want, make a pull request, or open an issue.
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class HomePage extends StatelessWidget {
onSelect: (Currency currency) {
print('Select currency: ${currency.name}');
},
favorite: ['SEK'],
);
},
child: const Text('Show currency picker'),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.0.0"
version: "2.0.1"
fake_async:
dependency: transitive
description:
Expand Down
3 changes: 3 additions & 0 deletions lib/currency_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export 'package:currency_picker/src/currency_utils.dart';
/// `showCurrencyName`: Option to show/hide the currency name, default value true (optional).
/// `showCurrencyCode`: Option to show/hide the currency code, default value true (optional).
/// `currencyFilter`: Can be used to uses filter the Currency list (optional).
/// `favorite`: The Currencies that will appear at the top of the list (optional).
///
/// This example demonstrates how to use `showCurrencyPicker`
/// ```dart
Expand All @@ -34,6 +35,7 @@ export 'package:currency_picker/src/currency_utils.dart';
void showCurrencyPicker({
required BuildContext context,
required ValueChanged<Currency> onSelect,
List<String>? favorite,
List<String>? currencyFilter,
String? searchHint,
bool showFlag = true,
Expand All @@ -49,6 +51,7 @@ void showCurrencyPicker({
showFlag: showFlag,
showCurrencyName: showCurrencyName,
showCurrencyCode: showCurrencyCode,
favorite: favorite,
currencyFilter: currencyFilter,
);
}
Expand Down
10 changes: 8 additions & 2 deletions lib/src/currency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ class Currency {

///The currency flag code
///
/// To get flag unicode(Emoji ) use [CurrencyUtils.countryCodeToEmoji]
/// To get flag unicode(Emoji) use [CurrencyUtils.countryCodeToEmoji]
final String flag;

///The currency number
final String number;

Currency({required this.code, required this.name, required this.symbol, required this.flag, required this.number});
Currency({
required this.code,
required this.name,
required this.symbol,
required this.flag,
required this.number,
});

Currency.from({required Map<String, dynamic> json})
: code = json['code'],
Expand Down
4 changes: 4 additions & 0 deletions lib/src/currency_list_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'currency_list_view.dart';
void showCurrencyListBottomSheet({
required BuildContext context,
required ValueChanged<Currency> onSelect,
List<String>? favorite,
List<String>? currencyFilter,
String? searchHint,
bool showFlag = true,
Expand All @@ -19,6 +20,7 @@ void showCurrencyListBottomSheet({
builder: (_) => _builder(
context,
onSelect,
favorite,
currencyFilter,
searchHint,
showFlag,
Expand All @@ -31,6 +33,7 @@ void showCurrencyListBottomSheet({
Widget _builder(
BuildContext context,
ValueChanged<Currency> onSelect,
List<String>? favorite,
List<String>? currencyFilter,
String? searchHint,
bool showFlag,
Expand Down Expand Up @@ -65,6 +68,7 @@ Widget _builder(
showFlag: showFlag,
showCurrencyName: showCurrencyName,
showCurrencyCode: showCurrencyCode,
favorite: favorite,
currencyFilter: currencyFilter,
),
);
Expand Down
28 changes: 25 additions & 3 deletions lib/src/currency_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class CurrencyListView extends StatefulWidget {
/// The currency picker passes the new value to the callback.
final ValueChanged<Currency> onSelect;

/// The Currencies that will appear at the top of the list (optional).
///
/// It takes a list of Currency code.
final List<String>? favorite;

/// Can be used to uses filter the Currency list (optional).
///
/// It takes a list of Currency code.
Expand Down Expand Up @@ -40,6 +45,7 @@ class CurrencyListView extends StatefulWidget {
const CurrencyListView({
Key? key,
required this.onSelect,
this.favorite,
this.currencyFilter,
this.searchHint,
this.showCurrencyCode = true,
Expand All @@ -56,6 +62,7 @@ class _CurrencyListViewState extends State<CurrencyListView> {

late List<Currency> _filteredList;
late List<Currency> _currencyList;
List<Currency>? _favoriteList;

TextEditingController? _searchController;

Expand All @@ -75,6 +82,10 @@ class _CurrencyListViewState extends State<CurrencyListView> {
.removeWhere((element) => !currencyFilter.contains(element.code));
}

if (widget.favorite != null) {
_favoriteList = _currencyService.findCurrenciesByCode(widget.favorite!);
}

_filteredList.addAll(_currencyList);
super.initState();
}
Expand Down Expand Up @@ -109,9 +120,20 @@ class _CurrencyListViewState extends State<CurrencyListView> {
),
Expanded(
child: ListView(
children: _filteredList
.map<Widget>((currency) => _listRow(currency))
.toList(),
children: [
if (_favoriteList != null) ...[
..._favoriteList!
.map<Widget>((currency) => _listRow(currency))
.toList(),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: Divider(thickness: 1),
),
],
..._filteredList
.map<Widget>((currency) => _listRow(currency))
.toList()
],
),
),
],
Expand Down
14 changes: 14 additions & 0 deletions lib/src/currency_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,18 @@ class CurrencyService {
return _currencies
.firstWhereOrNull((currency) => currency.number == number);
}

///Returns a list with all the currencies that mach the given codes list.
List<Currency> findCurrenciesByCode(List<String> codes) {
final List<String> _codes =
codes.map((code) => code.toUpperCase()).toList();
final List<Currency> currencies = [];
for (final code in _codes) {
final Currency? currency = findByCode(code);
if (currency != null) {
currencies.add(currency);
}
}
return currencies;
}
}
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ packages:
name: lint
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.2"
version: "1.5.3"
matcher:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A flutter package to select a currency from a list of currencies.
homepage: https://github.com/Daniel-Ioannou
repository: https://github.com/Daniel-Ioannou/flutter_currency_picker

version: 2.0.0
version: 2.0.1

environment:
sdk: '>=2.12.0 <3.0.0'
Expand All @@ -18,6 +18,6 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
lint: ^1.5.2
lint: ^1.5.3

flutter:

0 comments on commit 6a3de83

Please sign in to comment.