2021-11-22 11:49:52 +03:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-01 16:07:09 +03:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2022-03-31 12:41:28 +03:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2021-11-22 11:49:52 +03:00
|
|
|
|
|
|
|
import '../../app/models.dart';
|
2022-06-02 15:52:00 +03:00
|
|
|
import '../../widgets/list_title.dart';
|
2021-11-22 11:49:52 +03:00
|
|
|
import '../models.dart';
|
2022-03-31 12:41:28 +03:00
|
|
|
import '../state.dart';
|
2021-11-22 11:49:52 +03:00
|
|
|
import 'account_view.dart';
|
|
|
|
|
2022-07-07 13:40:54 +03:00
|
|
|
class AccountList extends ConsumerWidget {
|
2022-03-28 13:58:45 +03:00
|
|
|
final DevicePath devicePath;
|
|
|
|
final OathState oathState;
|
2022-05-12 10:56:55 +03:00
|
|
|
const AccountList(this.devicePath, this.oathState, {super.key});
|
2021-11-22 11:49:52 +03:00
|
|
|
|
2022-02-10 14:11:44 +03:00
|
|
|
@override
|
2022-07-07 13:40:54 +03:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final accounts = ref.watch(credentialListProvider(devicePath));
|
2022-03-31 12:41:28 +03:00
|
|
|
if (accounts == null) {
|
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: const [
|
|
|
|
Center(child: CircularProgressIndicator()),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
final credentials = ref.watch(filteredCredentialsProvider(accounts));
|
|
|
|
final favorites = ref.watch(favoritesProvider);
|
|
|
|
if (credentials.isEmpty) {
|
2022-09-01 16:07:09 +03:00
|
|
|
return Center(
|
|
|
|
child: Text(AppLocalizations.of(context)!.oath_no_credentials),
|
2021-11-22 11:49:52 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-03-31 12:41:28 +03:00
|
|
|
final pinnedCreds =
|
|
|
|
credentials.where((entry) => favorites.contains(entry.credential.id));
|
|
|
|
final creds =
|
|
|
|
credentials.where((entry) => !favorites.contains(entry.credential.id));
|
2022-02-10 14:11:44 +03:00
|
|
|
|
2022-07-07 13:40:54 +03:00
|
|
|
return FocusTraversalGroup(
|
|
|
|
policy: WidgetOrderTraversalPolicy(),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2022-09-01 16:07:09 +03:00
|
|
|
if (pinnedCreds.isNotEmpty)
|
|
|
|
ListTitle(AppLocalizations.of(context)!.oath_pinned),
|
2022-07-07 13:40:54 +03:00
|
|
|
...pinnedCreds.map(
|
|
|
|
(entry) => AccountView(
|
|
|
|
entry.credential,
|
|
|
|
),
|
2022-02-10 14:11:44 +03:00
|
|
|
),
|
2022-09-01 16:07:09 +03:00
|
|
|
if (creds.isNotEmpty)
|
|
|
|
ListTitle(AppLocalizations.of(context)!.oath_accounts),
|
2022-07-07 13:40:54 +03:00
|
|
|
...creds.map(
|
|
|
|
(entry) => AccountView(
|
|
|
|
entry.credential,
|
|
|
|
),
|
2022-02-10 14:11:44 +03:00
|
|
|
),
|
2022-07-07 13:40:54 +03:00
|
|
|
],
|
|
|
|
),
|
2021-11-22 11:49:52 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|