Skip to content

Commit

Permalink
Handle fallback and initial state (with empty db)
Browse files Browse the repository at this point in the history
  • Loading branch information
K-w-e committed Feb 12, 2024
1 parent 3c0a00f commit d97a342
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/model/currency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ class CurrencyMethods extends SossoldiDatabase {
if (maps.isNotEmpty) {
return Currency.fromJson(maps.first);
} else {
throw Exception('No valid currency found');
//fallback
return const Currency(
id: 2,
symbol: '\$',
code: 'USD',
name: "United States Dollar",
mainCurrency: true
);
}
}

Expand Down
9 changes: 8 additions & 1 deletion lib/providers/currency_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ final currencyStateNotifier = ChangeNotifierProvider(
);

class CurrencyState extends ChangeNotifier {
late Currency selectedCurrency;
//Initial currency selected
Currency selectedCurrency = const Currency(
id: 2,
symbol: '\$',
code: 'USD',
name: "United States Dollar",
mainCurrency: true
);

CurrencyState() {
_initializeState();
Expand Down

0 comments on commit d97a342

Please sign in to comment.