-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: start with Riverpod integration
- Loading branch information
1 parent
79d919e
commit e739166
Showing
54 changed files
with
3,273 additions
and
2,923 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
"icalendar", | ||
"Imap", | ||
"LTRB", | ||
"Maily" | ||
"Maily", | ||
"riverpod", | ||
"unawaited" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:enough_mail_app/models/account.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'providers.g.dart'; | ||
|
||
/// Retrieves the list of real accounts | ||
@Riverpod(keepAlive: true) | ||
List<RealAccount> realAccounts(RealAccountsRef ref) { | ||
throw UnimplementedError(); | ||
} | ||
|
||
/// Retrieves the current account | ||
@riverpod | ||
Raw<Account?> currentAccount(CurrentAccountRef ref) { | ||
throw UnimplementedError(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | ||
|
||
import '../models/account.dart'; | ||
|
||
/// Allows to load and store accounts | ||
class AccountStorage { | ||
/// Creates a new [AccountStorage] | ||
const AccountStorage(); | ||
|
||
static const String _keyAccounts = 'accts'; | ||
final _storage = const FlutterSecureStorage(); | ||
|
||
/// Loads the accounts from the storage | ||
Future<List<RealAccount>> loadAccounts() async { | ||
final jsonText = await _storage.read(key: _keyAccounts); | ||
if (jsonText == null) { | ||
return <RealAccount>[]; | ||
} | ||
final accountsJson = jsonDecode(jsonText) as List; | ||
try { | ||
return accountsJson.map((json) => RealAccount.fromJson(json)).toList(); | ||
} catch (e) { | ||
if (kDebugMode) { | ||
print('Unable to parse accounts: $e'); | ||
print(jsonText); | ||
} | ||
return <RealAccount>[]; | ||
} | ||
} | ||
|
||
/// Saves the given [accounts] to the storage | ||
Future<void> saveAccounts(List<Account> accounts) { | ||
final accountsJson = | ||
accounts.whereType<RealAccount>().map((a) => (a).toJson()).toList(); | ||
final json = jsonEncode(accountsJson); | ||
return _storage.write(key: _keyAccounts, value: json); | ||
} | ||
} |
Oops, something went wrong.