yubioath-flutter/lib/oath/views/account_list.dart

63 lines
1.8 KiB
Dart
Raw Normal View History

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';
import '../../app/models.dart';
import '../../widgets/list_title.dart';
import '../models.dart';
2022-03-31 12:41:28 +03:00
import '../state.dart';
import 'account_view.dart';
2022-07-07 13:40:54 +03:00
class AccountList extends ConsumerWidget {
final DevicePath devicePath;
final OathState oathState;
2022-05-12 10:56:55 +03:00
const AccountList(this.devicePath, this.oathState, {super.key});
@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),
);
}
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-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-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-07-07 13:40:54 +03:00
],
),
);
}
}