2022-10-04 13:12:54 +03:00
|
|
|
/*
|
2024-04-16 11:38:43 +03:00
|
|
|
* Copyright (C) 2022-2024 Yubico.
|
2022-10-04 13:12:54 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2024-01-17 18:29:28 +03:00
|
|
|
import 'dart:async';
|
2024-01-10 18:06:12 +03:00
|
|
|
import 'dart:io';
|
2023-12-22 18:46:29 +03:00
|
|
|
|
2021-11-22 11:49:52 +03:00
|
|
|
import 'package:flutter/material.dart';
|
2022-03-25 18:24:15 +03:00
|
|
|
import 'package:flutter/services.dart';
|
2022-09-06 15:30:18 +03:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2021-11-22 11:49:52 +03:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2024-03-08 11:30:47 +03:00
|
|
|
import 'package:material_symbols_icons/symbols.dart';
|
2021-11-22 11:49:52 +03:00
|
|
|
|
2023-12-22 18:46:29 +03:00
|
|
|
import '../../app/message.dart';
|
2021-11-22 11:49:52 +03:00
|
|
|
import '../../app/models.dart';
|
2022-06-10 14:49:02 +03:00
|
|
|
import '../../app/shortcuts.dart';
|
2023-12-22 18:46:29 +03:00
|
|
|
import '../../app/state.dart';
|
2024-01-17 18:29:28 +03:00
|
|
|
import '../../app/views/action_list.dart';
|
2022-05-20 18:19:39 +03:00
|
|
|
import '../../app/views/app_failure_page.dart';
|
2022-03-25 18:24:15 +03:00
|
|
|
import '../../app/views/app_page.dart';
|
2024-03-21 14:22:46 +03:00
|
|
|
import '../../app/views/keys.dart';
|
2022-04-05 12:46:22 +03:00
|
|
|
import '../../app/views/message_page.dart';
|
2024-03-11 13:09:15 +03:00
|
|
|
import '../../app/views/message_page_not_initialized.dart';
|
2023-09-29 15:12:11 +03:00
|
|
|
import '../../core/state.dart';
|
2024-03-13 12:36:50 +03:00
|
|
|
import '../../exception/no_data_exception.dart';
|
2024-01-23 14:28:21 +03:00
|
|
|
import '../../management/models.dart';
|
2023-12-14 19:40:29 +03:00
|
|
|
import '../../widgets/app_input_decoration.dart';
|
2023-11-10 17:24:53 +03:00
|
|
|
import '../../widgets/app_text_form_field.dart';
|
2024-01-08 16:11:32 +03:00
|
|
|
import '../../widgets/file_drop_overlay.dart';
|
2024-01-17 18:29:28 +03:00
|
|
|
import '../../widgets/list_title.dart';
|
2024-04-25 16:26:33 +03:00
|
|
|
import '../../widgets/tooltip_if_truncated.dart';
|
2023-09-29 15:12:11 +03:00
|
|
|
import '../features.dart' as features;
|
2022-09-12 13:58:17 +03:00
|
|
|
import '../keys.dart' as keys;
|
2022-03-25 18:24:15 +03:00
|
|
|
import '../models.dart';
|
2021-11-22 11:49:52 +03:00
|
|
|
import '../state.dart';
|
2024-01-17 18:29:28 +03:00
|
|
|
import 'account_dialog.dart';
|
|
|
|
import 'account_helper.dart';
|
2021-11-22 11:49:52 +03:00
|
|
|
import 'account_list.dart';
|
2024-01-17 18:29:28 +03:00
|
|
|
import 'actions.dart';
|
2023-01-12 10:56:08 +03:00
|
|
|
import 'key_actions.dart';
|
2022-09-14 14:19:39 +03:00
|
|
|
import 'unlock_form.dart';
|
2023-12-22 18:46:29 +03:00
|
|
|
import 'utils.dart';
|
2021-11-22 11:49:52 +03:00
|
|
|
|
2024-07-01 17:21:21 +03:00
|
|
|
extension on OathLayout {
|
|
|
|
IconData get _icon => switch (this) {
|
|
|
|
OathLayout.list => Symbols.list,
|
|
|
|
OathLayout.grid => Symbols.grid_view,
|
|
|
|
OathLayout.mixed => Symbols.vertical_split
|
|
|
|
};
|
|
|
|
String getDisplayName(AppLocalizations l10n) => switch (this) {
|
|
|
|
OathLayout.list => l10n.s_list_layout,
|
|
|
|
OathLayout.grid => l10n.s_grid_layout,
|
|
|
|
OathLayout.mixed => l10n.s_mixed_layout
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-22 11:49:52 +03:00
|
|
|
class OathScreen extends ConsumerWidget {
|
2022-04-03 12:06:22 +03:00
|
|
|
final DevicePath devicePath;
|
2022-10-18 12:52:02 +03:00
|
|
|
|
2022-05-12 10:56:55 +03:00
|
|
|
const OathScreen(this.devicePath, {super.key});
|
2021-11-22 11:49:52 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2024-03-11 13:09:15 +03:00
|
|
|
final l10n = AppLocalizations.of(context)!;
|
2022-04-03 12:06:22 +03:00
|
|
|
return ref.watch(oathStateProvider(devicePath)).when(
|
2024-04-15 18:09:56 +03:00
|
|
|
loading: () => MessagePage(
|
|
|
|
title: AppLocalizations.of(context)!.s_accounts,
|
|
|
|
capabilities: const [Capability.oath],
|
2024-03-12 20:00:06 +03:00
|
|
|
centered: true,
|
2024-04-15 18:09:56 +03:00
|
|
|
graphic: const CircularProgressIndicator(),
|
2024-03-12 20:00:06 +03:00
|
|
|
delayedContent: true,
|
|
|
|
),
|
2024-03-13 12:36:50 +03:00
|
|
|
error: (error, _) => error is NoDataException
|
2024-04-12 16:59:47 +03:00
|
|
|
? MessagePageNotInitialized(
|
|
|
|
title: l10n.s_accounts,
|
|
|
|
capabilities: const [Capability.oath],
|
|
|
|
)
|
2024-03-12 20:00:06 +03:00
|
|
|
: AppFailurePage(
|
|
|
|
cause: error,
|
|
|
|
),
|
|
|
|
data: (oathState) => oathState.locked
|
|
|
|
? _LockedView(devicePath, oathState)
|
|
|
|
: _UnlockedView(devicePath, oathState));
|
2022-03-31 12:41:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LockedView extends ConsumerWidget {
|
|
|
|
final DevicePath devicePath;
|
|
|
|
final OathState oathState;
|
|
|
|
|
2024-01-05 13:16:10 +03:00
|
|
|
const _LockedView(this.devicePath, this.oathState);
|
2022-03-31 12:41:28 +03:00
|
|
|
|
|
|
|
@override
|
2023-01-12 10:56:08 +03:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-09-29 15:12:11 +03:00
|
|
|
final hasActions = ref.watch(featureProvider)(features.actions);
|
2023-01-12 10:56:08 +03:00
|
|
|
return AppPage(
|
2024-01-15 17:58:40 +03:00
|
|
|
title: AppLocalizations.of(context)!.s_accounts,
|
2024-01-26 13:59:37 +03:00
|
|
|
capabilities: const [Capability.oath],
|
2023-09-29 15:12:11 +03:00
|
|
|
keyActionsBuilder: hasActions
|
|
|
|
? (context) => oathBuildActions(context, devicePath, oathState, ref)
|
|
|
|
: null,
|
2024-01-10 23:05:54 +03:00
|
|
|
builder: (context, _) => Padding(
|
2024-01-15 17:58:40 +03:00
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
2023-01-12 10:56:08 +03:00
|
|
|
child: UnlockForm(
|
|
|
|
devicePath,
|
|
|
|
keystore: oathState.keystore,
|
2022-04-03 12:06:22 +03:00
|
|
|
),
|
2023-01-12 10:56:08 +03:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-03-31 12:41:28 +03:00
|
|
|
}
|
|
|
|
|
2022-06-09 12:52:54 +03:00
|
|
|
class _UnlockedView extends ConsumerStatefulWidget {
|
2022-03-31 12:41:28 +03:00
|
|
|
final DevicePath devicePath;
|
|
|
|
final OathState oathState;
|
|
|
|
|
2024-01-05 13:16:10 +03:00
|
|
|
const _UnlockedView(this.devicePath, this.oathState);
|
2022-03-31 12:41:28 +03:00
|
|
|
|
|
|
|
@override
|
2022-06-09 12:52:54 +03:00
|
|
|
ConsumerState<ConsumerStatefulWidget> createState() => _UnlockedViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UnlockedViewState extends ConsumerState<_UnlockedView> {
|
|
|
|
late FocusNode searchFocus;
|
|
|
|
late TextEditingController searchController;
|
2024-01-17 18:29:28 +03:00
|
|
|
OathCredential? _selected;
|
2024-06-13 10:29:30 +03:00
|
|
|
bool _canRequestFocus = true;
|
2022-06-09 12:52:54 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
searchFocus = FocusNode();
|
2024-03-20 19:01:26 +03:00
|
|
|
searchController =
|
|
|
|
TextEditingController(text: ref.read(accountsSearchProvider));
|
2023-12-20 17:09:31 +03:00
|
|
|
searchFocus.addListener(_onFocusChange);
|
2022-06-09 12:52:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
searchFocus.dispose();
|
|
|
|
searchController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2024-09-04 18:46:48 +03:00
|
|
|
void _scrollSearchField() {
|
|
|
|
// Ensures the search field is fully visible when in focus
|
|
|
|
final headerSliverContext = headerSliverGlobalKey.currentContext;
|
|
|
|
if (searchFocus.hasFocus && headerSliverContext != null) {
|
|
|
|
final scrollable = Scrollable.of(headerSliverContext);
|
|
|
|
if (scrollable.deltaToScrollOrigin.dy > 0) {
|
2024-09-05 15:49:07 +03:00
|
|
|
scrollable.position.animateTo(
|
|
|
|
0,
|
|
|
|
duration: const Duration(milliseconds: 100),
|
|
|
|
curve: Curves.ease,
|
|
|
|
);
|
2024-09-04 18:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-20 17:09:31 +03:00
|
|
|
void _onFocusChange() {
|
2024-09-04 18:46:48 +03:00
|
|
|
_scrollSearchField();
|
2023-12-20 17:09:31 +03:00
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
2022-06-09 12:52:54 +03:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-02-28 21:05:46 +03:00
|
|
|
final l10n = AppLocalizations.of(context)!;
|
2022-09-29 15:30:20 +03:00
|
|
|
// ONLY rebuild if the number of credentials changes.
|
|
|
|
final numCreds = ref.watch(credentialListProvider(widget.devicePath)
|
|
|
|
.select((value) => value?.length));
|
2024-01-17 18:29:28 +03:00
|
|
|
final hasFeature = ref.watch(featureProvider);
|
|
|
|
final hasActions = hasFeature(features.actions);
|
2024-02-28 16:49:16 +03:00
|
|
|
final searchText = searchController.text;
|
2024-08-21 18:09:40 +03:00
|
|
|
final deviceInfo =
|
|
|
|
ref.watch(currentDeviceDataProvider.select((s) => s.valueOrNull?.info));
|
2024-01-10 18:06:12 +03:00
|
|
|
Future<void> onFileDropped(File file) async {
|
2024-01-09 14:17:37 +03:00
|
|
|
final qrScanner = ref.read(qrScannerProvider);
|
2024-01-05 13:16:10 +03:00
|
|
|
if (qrScanner != null) {
|
2024-01-09 14:17:37 +03:00
|
|
|
final withContext = ref.read(withContextProvider);
|
2024-01-24 11:44:05 +03:00
|
|
|
final qrData =
|
|
|
|
await handleQrFile(file, context, withContext, qrScanner);
|
|
|
|
if (qrData != null) {
|
|
|
|
await withContext((context) async {
|
|
|
|
final credentials = ref.read(credentialsProvider);
|
|
|
|
await handleUri(context, credentials, qrData, widget.devicePath,
|
|
|
|
widget.oathState, l10n);
|
|
|
|
});
|
|
|
|
}
|
2024-01-05 13:16:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-29 15:30:20 +03:00
|
|
|
if (numCreds == 0) {
|
2022-04-05 12:46:22 +03:00
|
|
|
return MessagePage(
|
2024-08-21 18:09:40 +03:00
|
|
|
keyActionsBadge: oathShowActionNotifier(deviceInfo),
|
2024-08-21 16:13:13 +03:00
|
|
|
actionsBuilder: (context, expanded) {
|
2024-08-21 18:09:40 +03:00
|
|
|
final (fipsCapable, fipsApproved) =
|
|
|
|
deviceInfo?.getFipsStatus(Capability.oath) ?? (false, false);
|
|
|
|
|
2024-08-21 16:13:13 +03:00
|
|
|
return [
|
|
|
|
if (!expanded && (!fipsCapable || (fipsCapable && fipsApproved)))
|
|
|
|
ActionChip(
|
|
|
|
label: Text(l10n.s_add_account),
|
|
|
|
onPressed: () async {
|
|
|
|
await addOathAccount(
|
|
|
|
context,
|
|
|
|
ref,
|
|
|
|
widget.devicePath,
|
|
|
|
widget.oathState,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
avatar: const Icon(Symbols.person_add_alt),
|
|
|
|
),
|
|
|
|
if (!expanded && fipsCapable && !fipsApproved)
|
|
|
|
ActionChip(
|
|
|
|
label: Text(l10n.s_set_password),
|
|
|
|
onPressed: () async {
|
2024-08-26 09:20:04 +03:00
|
|
|
await managePassword(
|
2024-08-21 16:13:13 +03:00
|
|
|
context, ref, widget.devicePath, widget.oathState);
|
|
|
|
},
|
|
|
|
avatar: const Icon(Symbols.person_add_alt),
|
|
|
|
)
|
|
|
|
];
|
|
|
|
},
|
2024-01-18 14:16:15 +03:00
|
|
|
title: l10n.s_accounts,
|
2024-01-26 13:59:37 +03:00
|
|
|
capabilities: const [Capability.oath],
|
2022-09-12 13:58:17 +03:00
|
|
|
key: keys.noAccountsView,
|
2024-01-18 14:16:15 +03:00
|
|
|
header: l10n.l_authenticator_get_started,
|
2024-01-29 16:58:00 +03:00
|
|
|
message: l10n.l_no_accounts_desc,
|
2023-09-29 15:12:11 +03:00
|
|
|
keyActionsBuilder: hasActions
|
|
|
|
? (context) => oathBuildActions(
|
|
|
|
context, widget.devicePath, widget.oathState, ref,
|
|
|
|
used: 0)
|
|
|
|
: null,
|
2024-01-05 13:16:10 +03:00
|
|
|
onFileDropped: onFileDropped,
|
2024-01-08 16:11:32 +03:00
|
|
|
fileDropOverlay: FileDropOverlay(
|
|
|
|
title: l10n.s_add_account,
|
2024-01-09 14:17:37 +03:00
|
|
|
subtitle: l10n.l_drop_qr_description,
|
2024-01-08 16:11:32 +03:00
|
|
|
),
|
2022-03-31 12:41:28 +03:00
|
|
|
);
|
2022-04-05 12:46:22 +03:00
|
|
|
}
|
2024-01-17 18:29:28 +03:00
|
|
|
|
2024-01-30 19:16:08 +03:00
|
|
|
if (numCreds == null) {
|
|
|
|
return AppPage(
|
2024-04-15 09:59:07 +03:00
|
|
|
title: AppLocalizations.of(context)!.s_accounts,
|
|
|
|
capabilities: const [Capability.oath],
|
2024-01-30 19:16:08 +03:00
|
|
|
centered: true,
|
|
|
|
delayedContent: true,
|
2024-08-21 18:09:40 +03:00
|
|
|
keyActionsBadge: oathShowActionNotifier(deviceInfo),
|
2024-01-30 19:16:08 +03:00
|
|
|
builder: (context, _) => const CircularProgressIndicator(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-01-18 16:46:15 +03:00
|
|
|
return OathActions(
|
|
|
|
devicePath: widget.devicePath,
|
|
|
|
actions: (context) => {
|
|
|
|
SearchIntent: CallbackAction<SearchIntent>(onInvoke: (_) {
|
|
|
|
searchController.selection = TextSelection(
|
|
|
|
baseOffset: 0, extentOffset: searchController.text.length);
|
2024-02-28 16:47:22 +03:00
|
|
|
searchFocus.unfocus();
|
|
|
|
Timer.run(() => searchFocus.requestFocus());
|
2024-01-18 16:46:15 +03:00
|
|
|
return null;
|
|
|
|
}),
|
|
|
|
EscapeIntent: CallbackAction<EscapeIntent>(onInvoke: (intent) {
|
|
|
|
if (_selected != null) {
|
|
|
|
setState(() {
|
|
|
|
_selected = null;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Actions.invoke(context, intent);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}),
|
|
|
|
OpenIntent<OathCredential>: CallbackAction<OpenIntent<OathCredential>>(
|
|
|
|
onInvoke: (intent) async {
|
|
|
|
await showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
barrierColor: Colors.transparent,
|
|
|
|
builder: (context) => AccountDialog(intent.target),
|
|
|
|
);
|
|
|
|
return null;
|
|
|
|
}),
|
|
|
|
if (hasFeature(features.accountsRename))
|
|
|
|
EditIntent<OathCredential>:
|
|
|
|
CallbackAction<EditIntent<OathCredential>>(
|
|
|
|
onInvoke: (intent) async {
|
|
|
|
final renamed =
|
|
|
|
await (Actions.invoke(context, intent) as Future<dynamic>?);
|
|
|
|
if (renamed is OathCredential && _selected == intent.target) {
|
|
|
|
setState(() {
|
|
|
|
_selected = renamed;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return renamed;
|
2024-01-17 18:29:28 +03:00
|
|
|
}),
|
2024-01-18 16:46:15 +03:00
|
|
|
if (hasFeature(features.accountsDelete))
|
|
|
|
DeleteIntent<OathCredential>:
|
|
|
|
CallbackAction<DeleteIntent<OathCredential>>(
|
|
|
|
onInvoke: (intent) async {
|
|
|
|
final deleted =
|
|
|
|
await (Actions.invoke(context, intent) as Future<dynamic>?);
|
|
|
|
if (deleted == true && _selected == intent.target) {
|
2024-01-17 18:29:28 +03:00
|
|
|
setState(() {
|
|
|
|
_selected = null;
|
|
|
|
});
|
2022-07-07 13:40:54 +03:00
|
|
|
}
|
2024-01-18 16:46:15 +03:00
|
|
|
return deleted;
|
2024-01-17 18:29:28 +03:00
|
|
|
}),
|
2024-01-18 16:46:15 +03:00
|
|
|
},
|
|
|
|
builder: (context) => AppPage(
|
2024-01-15 17:58:40 +03:00
|
|
|
title: l10n.s_accounts,
|
2024-03-21 10:57:12 +03:00
|
|
|
alternativeTitle:
|
|
|
|
searchText != '' ? l10n.l_results_for(searchText) : null,
|
2024-01-26 13:59:37 +03:00
|
|
|
capabilities: const [Capability.oath],
|
2024-08-21 18:09:40 +03:00
|
|
|
keyActionsBadge: oathShowActionNotifier(deviceInfo),
|
2024-01-18 16:46:15 +03:00
|
|
|
keyActionsBuilder: hasActions
|
|
|
|
? (context) => oathBuildActions(
|
|
|
|
context,
|
|
|
|
widget.devicePath,
|
|
|
|
widget.oathState,
|
|
|
|
ref,
|
2024-01-30 19:16:08 +03:00
|
|
|
used: numCreds,
|
2024-01-18 16:46:15 +03:00
|
|
|
)
|
|
|
|
: null,
|
|
|
|
onFileDropped: onFileDropped,
|
|
|
|
fileDropOverlay: FileDropOverlay(
|
|
|
|
title: l10n.s_add_account,
|
|
|
|
subtitle: l10n.l_drop_qr_description,
|
|
|
|
),
|
|
|
|
detailViewBuilder: _selected != null
|
|
|
|
? (context) {
|
|
|
|
final helper = AccountHelper(context, ref, _selected!);
|
|
|
|
final subtitle = helper.subtitle;
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
ListTitle(l10n.s_details),
|
2024-01-23 14:28:21 +03:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 16.0),
|
|
|
|
child: Card(
|
|
|
|
elevation: 0.0,
|
|
|
|
color: Theme.of(context).hoverColor,
|
|
|
|
child: Padding(
|
2024-04-25 16:26:33 +03:00
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
vertical: 24, horizontal: 16),
|
2024-01-23 14:28:21 +03:00
|
|
|
child: Column(
|
|
|
|
children: [
|
2024-04-25 16:26:33 +03:00
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
IconTheme(
|
|
|
|
data: IconTheme.of(context)
|
|
|
|
.copyWith(size: 24),
|
|
|
|
child: helper.buildCodeIcon(),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 8.0),
|
|
|
|
DefaultTextStyle.merge(
|
|
|
|
style: const TextStyle(fontSize: 28),
|
|
|
|
child: helper.buildCodeLabel(),
|
|
|
|
),
|
|
|
|
],
|
2024-01-17 18:29:28 +03:00
|
|
|
),
|
2024-04-25 16:26:33 +03:00
|
|
|
const SizedBox(height: 16),
|
|
|
|
TooltipIfTruncated(
|
|
|
|
text: helper.title,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.headlineSmall
|
|
|
|
?.fontSize),
|
2024-01-17 18:29:28 +03:00
|
|
|
),
|
2024-01-23 14:28:21 +03:00
|
|
|
if (subtitle != null)
|
2024-04-25 16:26:33 +03:00
|
|
|
TooltipIfTruncated(
|
|
|
|
text: subtitle,
|
2024-01-23 14:28:21 +03:00
|
|
|
// This is what ListTile uses for subtitle
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyMedium!
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
2024-04-25 16:26:33 +03:00
|
|
|
.colorScheme
|
|
|
|
.onSurfaceVariant,
|
2024-01-23 14:28:21 +03:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2024-01-17 18:29:28 +03:00
|
|
|
),
|
|
|
|
),
|
2024-01-18 16:46:15 +03:00
|
|
|
),
|
|
|
|
ActionListSection.fromMenuActions(
|
|
|
|
context,
|
|
|
|
AppLocalizations.of(context)!.s_actions,
|
|
|
|
actions: helper.buildActions(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
: null,
|
2024-02-20 10:57:24 +03:00
|
|
|
headerSliver: Focus(
|
|
|
|
canRequestFocus: false,
|
|
|
|
onKeyEvent: (node, event) {
|
|
|
|
if (event.logicalKey == LogicalKeyboardKey.arrowDown) {
|
|
|
|
node.focusInDirection(TraversalDirection.down);
|
|
|
|
return KeyEventResult.handled;
|
|
|
|
}
|
|
|
|
if (event.logicalKey == LogicalKeyboardKey.escape) {
|
|
|
|
searchController.clear();
|
2024-03-20 19:01:26 +03:00
|
|
|
ref.read(accountsSearchProvider.notifier).setFilter('');
|
2024-02-20 10:57:24 +03:00
|
|
|
node.unfocus();
|
|
|
|
setState(() {});
|
|
|
|
return KeyEventResult.handled;
|
|
|
|
}
|
|
|
|
return KeyEventResult.ignored;
|
|
|
|
},
|
2024-07-01 17:21:21 +03:00
|
|
|
child: LayoutBuilder(builder: (context, constraints) {
|
|
|
|
final width = constraints.maxWidth;
|
2024-02-20 10:57:24 +03:00
|
|
|
final textTheme = Theme.of(context).textTheme;
|
2024-06-13 12:09:06 +03:00
|
|
|
return Consumer(
|
|
|
|
builder: (context, ref, child) {
|
|
|
|
final credentials = ref.watch(filteredCredentialsProvider(
|
|
|
|
ref.watch(credentialListProvider(widget.devicePath)) ??
|
|
|
|
[]));
|
|
|
|
final favorites = ref.watch(favoritesProvider);
|
|
|
|
final pinnedCreds = credentials
|
|
|
|
.where((entry) => favorites.contains(entry.credential.id));
|
2024-06-13 13:48:03 +03:00
|
|
|
|
2024-07-04 14:05:27 +03:00
|
|
|
final availableLayouts = pinnedCreds.isEmpty ||
|
|
|
|
pinnedCreds.length == credentials.length
|
2024-07-01 17:21:21 +03:00
|
|
|
? OathLayout.values
|
2024-07-04 14:05:27 +03:00
|
|
|
.where((element) => element != OathLayout.mixed)
|
|
|
|
: OathLayout.values;
|
2024-07-01 17:21:21 +03:00
|
|
|
final oathLayout = ref.watch(oathLayoutProvider);
|
2024-06-13 13:48:03 +03:00
|
|
|
|
2024-06-13 12:09:06 +03:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
2024-08-09 14:19:48 +03:00
|
|
|
horizontal: 10.0, vertical: 8.0),
|
2024-06-13 12:09:06 +03:00
|
|
|
child: AppTextFormField(
|
|
|
|
key: searchField,
|
|
|
|
controller: searchController,
|
|
|
|
canRequestFocus: _canRequestFocus,
|
|
|
|
focusNode: searchFocus,
|
|
|
|
// Use the default style, but with a smaller font size:
|
|
|
|
style: textTheme.titleMedium
|
|
|
|
?.copyWith(fontSize: textTheme.titleSmall?.fontSize),
|
|
|
|
decoration: AppInputDecoration(
|
|
|
|
border: OutlineInputBorder(
|
|
|
|
borderRadius: BorderRadius.circular(48),
|
|
|
|
borderSide: BorderSide(
|
|
|
|
width: 0,
|
|
|
|
style: searchFocus.hasFocus
|
|
|
|
? BorderStyle.solid
|
|
|
|
: BorderStyle.none,
|
2024-06-13 10:29:30 +03:00
|
|
|
),
|
|
|
|
),
|
2024-06-13 12:09:06 +03:00
|
|
|
contentPadding: const EdgeInsets.all(16),
|
|
|
|
fillColor: Theme.of(context).hoverColor,
|
|
|
|
filled: true,
|
|
|
|
hintText: l10n.s_search_accounts,
|
|
|
|
isDense: true,
|
|
|
|
prefixIcon: const Padding(
|
|
|
|
padding: EdgeInsetsDirectional.only(start: 8.0),
|
|
|
|
child: Icon(Icons.search_outlined),
|
2024-06-13 10:29:30 +03:00
|
|
|
),
|
2024-06-13 12:09:06 +03:00
|
|
|
suffixIcons: [
|
|
|
|
if (searchController.text.isNotEmpty)
|
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.clear),
|
|
|
|
iconSize: 16,
|
|
|
|
onPressed: () {
|
|
|
|
searchController.clear();
|
|
|
|
ref
|
|
|
|
.read(accountsSearchProvider.notifier)
|
|
|
|
.setFilter('');
|
|
|
|
setState(() {});
|
|
|
|
},
|
2024-06-13 11:35:29 +03:00
|
|
|
),
|
2024-08-08 14:06:34 +03:00
|
|
|
if (searchController.text.isEmpty) ...[
|
2024-07-04 14:58:13 +03:00
|
|
|
if (width >= 450)
|
2024-07-01 17:21:21 +03:00
|
|
|
...availableLayouts.map(
|
|
|
|
(e) => MouseRegion(
|
|
|
|
onEnter: (event) {
|
|
|
|
if (!searchFocus.hasFocus) {
|
|
|
|
setState(() {
|
|
|
|
_canRequestFocus = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onExit: (event) {
|
|
|
|
setState(() {
|
|
|
|
_canRequestFocus = true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: IconButton(
|
|
|
|
tooltip: e.getDisplayName(l10n),
|
|
|
|
onPressed: () {
|
|
|
|
ref
|
|
|
|
.read(oathLayoutProvider.notifier)
|
|
|
|
.setLayout(e);
|
|
|
|
},
|
|
|
|
icon: Icon(
|
|
|
|
e._icon,
|
|
|
|
color: e == oathLayout
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: null,
|
|
|
|
),
|
|
|
|
),
|
2024-06-13 12:09:06 +03:00
|
|
|
),
|
|
|
|
),
|
2024-07-04 14:58:13 +03:00
|
|
|
if (width < 450)
|
2024-06-13 12:09:06 +03:00
|
|
|
MouseRegion(
|
|
|
|
onEnter: (event) {
|
|
|
|
if (!searchFocus.hasFocus) {
|
|
|
|
setState(() {
|
|
|
|
_canRequestFocus = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onExit: (event) {
|
|
|
|
setState(() {
|
|
|
|
_canRequestFocus = true;
|
|
|
|
});
|
|
|
|
},
|
2024-07-01 17:21:21 +03:00
|
|
|
child: PopupMenuButton(
|
|
|
|
constraints: const BoxConstraints.tightFor(),
|
2024-08-21 16:43:57 +03:00
|
|
|
tooltip: l10n.s_select_layout,
|
2024-07-01 17:21:21 +03:00
|
|
|
popUpAnimationStyle:
|
|
|
|
AnimationStyle(duration: Duration.zero),
|
2024-06-13 12:09:06 +03:00
|
|
|
icon: Icon(
|
2024-07-01 17:21:21 +03:00
|
|
|
oathLayout._icon,
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
2024-06-13 12:09:06 +03:00
|
|
|
),
|
2024-07-01 17:21:21 +03:00
|
|
|
itemBuilder: (context) => [
|
|
|
|
...availableLayouts.map(
|
|
|
|
(e) => PopupMenuItem(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment:
|
|
|
|
MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Tooltip(
|
|
|
|
message: e.getDisplayName(l10n),
|
|
|
|
child: Icon(
|
|
|
|
e._icon,
|
|
|
|
color: e == oathLayout
|
|
|
|
? Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.primary
|
|
|
|
: null,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
ref
|
|
|
|
.read(oathLayoutProvider.notifier)
|
|
|
|
.setLayout(e);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2024-06-13 12:09:06 +03:00
|
|
|
),
|
2024-07-01 17:21:21 +03:00
|
|
|
)
|
2024-06-13 12:09:06 +03:00
|
|
|
]
|
|
|
|
],
|
|
|
|
),
|
2024-06-13 10:29:30 +03:00
|
|
|
|
2024-06-13 12:09:06 +03:00
|
|
|
onChanged: (value) {
|
|
|
|
ref
|
|
|
|
.read(accountsSearchProvider.notifier)
|
|
|
|
.setFilter(value);
|
2024-09-04 18:46:48 +03:00
|
|
|
_scrollSearchField();
|
2024-06-13 12:09:06 +03:00
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
textInputAction: TextInputAction.next,
|
|
|
|
onFieldSubmitted: (value) {
|
|
|
|
Focus.of(context)
|
|
|
|
.focusInDirection(TraversalDirection.down);
|
|
|
|
},
|
|
|
|
).init(),
|
|
|
|
);
|
|
|
|
},
|
2024-02-20 10:57:24 +03:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
),
|
2024-01-18 16:46:15 +03:00
|
|
|
builder: (context, expanded) {
|
|
|
|
// De-select if window is resized to be non-expanded.
|
2024-01-23 12:48:22 +03:00
|
|
|
if (!expanded && _selected != null) {
|
2024-01-18 16:46:15 +03:00
|
|
|
Timer.run(() {
|
|
|
|
setState(() {
|
|
|
|
_selected = null;
|
2024-01-17 18:29:28 +03:00
|
|
|
});
|
2024-01-18 16:46:15 +03:00
|
|
|
});
|
|
|
|
}
|
2024-01-30 19:16:08 +03:00
|
|
|
return Actions(
|
|
|
|
actions: {
|
|
|
|
if (expanded)
|
|
|
|
OpenIntent<OathCredential>:
|
|
|
|
CallbackAction<OpenIntent<OathCredential>>(
|
|
|
|
onInvoke: (OpenIntent<OathCredential> intent) {
|
|
|
|
setState(() {
|
|
|
|
_selected = intent.target;
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Consumer(
|
|
|
|
builder: (context, ref, _) {
|
|
|
|
return AccountList(
|
|
|
|
ref.watch(credentialListProvider(widget.devicePath)) ??
|
|
|
|
[],
|
|
|
|
expanded: expanded,
|
|
|
|
selected: _selected,
|
|
|
|
);
|
|
|
|
},
|
2024-01-18 16:46:15 +03:00
|
|
|
)
|
2024-01-30 19:16:08 +03:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2024-01-18 16:46:15 +03:00
|
|
|
},
|
2022-04-05 12:46:22 +03:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2021-11-22 11:49:52 +03:00
|
|
|
}
|