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

76 lines
2.3 KiB
Dart
Raw Normal View History

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.
*/
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 '../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 List<OathPair> accounts;
final bool expanded;
final OathCredential? selected;
const AccountList(this.accounts,
{super.key, required this.expanded, this.selected});
@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)!;
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(
child: Text(l10n.s_no_accounts),
);
}
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: [
...pinnedCreds.map(
(entry) => AccountView(
entry.credential,
expanded: expanded,
selected: entry.credential == selected,
2022-07-07 13:40:54 +03:00
),
),
if (pinnedCreds.isNotEmpty && creds.isNotEmpty)
2024-01-15 17:58:40 +03:00
const Padding(
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: Divider(),
),
2022-07-07 13:40:54 +03:00
...creds.map(
(entry) => AccountView(
entry.credential,
expanded: expanded,
selected: entry.credential == selected,
2022-07-07 13:40:54 +03:00
),
),
2022-07-07 13:40:54 +03:00
],
),
);
}
}