2022-10-04 13:12:54 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2022 Yubico.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2024-06-13 10:29:30 +03:00
|
|
|
import '../../widgets/flex_box.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-09-16 13:56:36 +03:00
|
|
|
final List<OathPair> accounts;
|
2024-01-17 18:29:28 +03:00
|
|
|
final bool expanded;
|
|
|
|
final OathCredential? selected;
|
|
|
|
const AccountList(this.accounts,
|
|
|
|
{super.key, required this.expanded, this.selected});
|
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) {
|
2023-02-28 21:05:46 +03:00
|
|
|
final l10n = AppLocalizations.of(context)!;
|
2024-07-04 15:31:43 +03:00
|
|
|
final theme = Theme.of(context);
|
|
|
|
final labelStyle =
|
|
|
|
theme.textTheme.bodyMedium?.copyWith(color: theme.colorScheme.primary);
|
2022-03-31 12:41:28 +03:00
|
|
|
final credentials = ref.watch(filteredCredentialsProvider(accounts));
|
|
|
|
final favorites = ref.watch(favoritesProvider);
|
|
|
|
if (credentials.isEmpty) {
|
2022-09-01 16:07:09 +03:00
|
|
|
return Center(
|
2023-03-02 14:45:55 +03:00
|
|
|
child: Text(l10n.s_no_accounts),
|
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
|
|
|
|
2024-07-01 17:21:21 +03:00
|
|
|
final oathLayout = ref.watch(oathLayoutProvider);
|
|
|
|
final pinnedLayout =
|
|
|
|
(oathLayout == OathLayout.grid || oathLayout == OathLayout.mixed)
|
|
|
|
? FlexLayout.grid
|
|
|
|
: FlexLayout.list;
|
|
|
|
final normalLayout =
|
|
|
|
oathLayout == OathLayout.grid ? FlexLayout.grid : FlexLayout.list;
|
2024-06-13 10:29:30 +03:00
|
|
|
|
2022-07-07 13:40:54 +03:00
|
|
|
return FocusTraversalGroup(
|
|
|
|
policy: WidgetOrderTraversalPolicy(),
|
2024-05-02 17:10:56 +03:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8.0),
|
|
|
|
child: Column(
|
2024-07-04 15:31:43 +03:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2024-05-02 17:10:56 +03:00
|
|
|
children: [
|
2024-07-04 15:31:43 +03:00
|
|
|
if (pinnedCreds.isNotEmpty) ...[
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 16, bottom: 8),
|
|
|
|
child: Text(l10n.s_pinned, style: labelStyle),
|
|
|
|
),
|
2024-06-13 10:29:30 +03:00
|
|
|
Padding(
|
|
|
|
padding: pinnedLayout == FlexLayout.grid
|
|
|
|
? const EdgeInsets.only(left: 16.0, right: 16)
|
|
|
|
: const EdgeInsets.all(0),
|
|
|
|
child: FlexBox<OathPair>(
|
|
|
|
items: pinnedCreds.toList(),
|
|
|
|
itemBuilder: (value) => AccountView(
|
|
|
|
value.credential,
|
|
|
|
expanded: expanded,
|
|
|
|
selected: value.credential == selected,
|
|
|
|
large: pinnedLayout == FlexLayout.grid,
|
|
|
|
),
|
|
|
|
layout: pinnedLayout,
|
2024-06-14 14:04:55 +03:00
|
|
|
runSpacing: 8.0,
|
2024-06-13 10:29:30 +03:00
|
|
|
),
|
|
|
|
),
|
2024-07-04 15:31:43 +03:00
|
|
|
],
|
|
|
|
if (pinnedCreds.isNotEmpty && creds.isNotEmpty) ...[
|
2024-06-14 11:23:18 +03:00
|
|
|
const SizedBox(height: 24),
|
2024-07-04 15:31:43 +03:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 16, bottom: 8),
|
|
|
|
child: Text(
|
|
|
|
l10n.s_accounts,
|
|
|
|
style: labelStyle,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2024-06-13 10:29:30 +03:00
|
|
|
Padding(
|
2024-07-01 17:21:21 +03:00
|
|
|
padding: normalLayout == FlexLayout.grid
|
2024-06-13 10:29:30 +03:00
|
|
|
? const EdgeInsets.only(left: 16.0, right: 16)
|
|
|
|
: const EdgeInsets.all(0),
|
|
|
|
child: FlexBox<OathPair>(
|
|
|
|
items: creds.toList(),
|
|
|
|
itemBuilder: (value) => AccountView(
|
|
|
|
value.credential,
|
|
|
|
expanded: expanded,
|
|
|
|
selected: value.credential == selected,
|
2024-07-01 17:21:21 +03:00
|
|
|
large: normalLayout == FlexLayout.grid,
|
2024-06-13 10:29:30 +03:00
|
|
|
),
|
2024-07-01 17:21:21 +03:00
|
|
|
layout: normalLayout,
|
2024-06-14 14:04:55 +03:00
|
|
|
runSpacing: 8.0,
|
2024-02-20 10:57:24 +03:00
|
|
|
),
|
2024-01-15 17:58:40 +03:00
|
|
|
),
|
2024-05-02 17:10:56 +03:00
|
|
|
],
|
|
|
|
),
|
2022-07-07 13:40:54 +03:00
|
|
|
),
|
2021-11-22 11:49:52 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|