2023-08-16 10:47:25 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2023 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';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2024-03-08 11:30:47 +03:00
|
|
|
import 'package:material_symbols_icons/symbols.dart';
|
2023-08-16 10:47:25 +03:00
|
|
|
|
2023-11-27 13:41:05 +03:00
|
|
|
import '../../app/message.dart';
|
2023-08-16 10:47:25 +03:00
|
|
|
import '../../app/models.dart';
|
2023-11-27 13:41:05 +03:00
|
|
|
import '../../app/state.dart';
|
2024-01-08 16:11:32 +03:00
|
|
|
import '../../widgets/file_drop_overlay.dart';
|
2023-08-16 10:47:25 +03:00
|
|
|
import '../../widgets/file_drop_target.dart';
|
2023-11-27 13:41:05 +03:00
|
|
|
import '../../widgets/responsive_dialog.dart';
|
2023-11-14 18:44:14 +03:00
|
|
|
import '../keys.dart';
|
2023-08-16 10:47:25 +03:00
|
|
|
import '../models.dart';
|
|
|
|
import '../state.dart';
|
|
|
|
import 'add_account_page.dart';
|
2023-08-16 13:38:29 +03:00
|
|
|
import 'utils.dart';
|
2023-08-16 10:47:25 +03:00
|
|
|
|
|
|
|
class AddAccountDialog extends ConsumerStatefulWidget {
|
|
|
|
final DevicePath? devicePath;
|
|
|
|
final OathState? state;
|
|
|
|
|
|
|
|
const AddAccountDialog(this.devicePath, this.state, {super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<ConsumerStatefulWidget> createState() =>
|
|
|
|
_AddAccountDialogState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AddAccountDialogState extends ConsumerState<AddAccountDialog> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final l10n = AppLocalizations.of(context)!;
|
|
|
|
final credentials = ref.read(credentialsProvider);
|
|
|
|
final withContext = ref.read(withContextProvider);
|
|
|
|
|
|
|
|
final qrScanner = ref.watch(qrScannerProvider);
|
2024-01-05 13:16:10 +03:00
|
|
|
return FileDropTarget(
|
2024-01-10 18:06:12 +03:00
|
|
|
onFileDropped: (file) async {
|
2024-01-05 13:16:10 +03:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
if (qrScanner != null) {
|
2024-01-24 11:44:05 +03:00
|
|
|
final qrData =
|
|
|
|
await handleQrFile(file, context, withContext, qrScanner);
|
|
|
|
if (qrData != null) {
|
|
|
|
await withContext((context) async {
|
|
|
|
await handleUri(context, credentials, qrData, widget.devicePath,
|
|
|
|
widget.state, l10n);
|
|
|
|
});
|
|
|
|
}
|
2024-01-05 13:16:10 +03:00
|
|
|
}
|
|
|
|
},
|
2024-01-08 16:11:32 +03:00
|
|
|
overlay: 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
|
|
|
),
|
2024-01-05 13:16:10 +03:00
|
|
|
child: ResponsiveDialog(
|
2023-08-16 10:47:25 +03:00
|
|
|
title: Text(l10n.s_add_account),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 18.0),
|
2024-01-05 13:16:10 +03:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(l10n.p_add_description),
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
Wrap(
|
|
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
|
|
spacing: 4.0,
|
|
|
|
runSpacing: 8.0,
|
|
|
|
children: [
|
|
|
|
ActionChip(
|
2024-03-08 11:30:47 +03:00
|
|
|
avatar: const Icon(Symbols.qr_code_scanner),
|
2024-01-05 13:16:10 +03:00
|
|
|
label: Text(l10n.s_qr_scan),
|
|
|
|
onPressed: () async {
|
|
|
|
if (qrScanner != null) {
|
|
|
|
final qrData = await qrScanner.scanQr();
|
|
|
|
await withContext(
|
|
|
|
(context) async {
|
|
|
|
if (qrData != null) {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
await handleUri(context, credentials, qrData,
|
|
|
|
widget.devicePath, widget.state, l10n);
|
|
|
|
} else {
|
|
|
|
showMessage(context, l10n.l_qr_not_found);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ActionChip(
|
|
|
|
key: addAccountManuallyButton,
|
2024-03-08 11:30:47 +03:00
|
|
|
avatar: const Icon(Symbols.edit),
|
2024-01-05 13:16:10 +03:00
|
|
|
label: Text(l10n.s_add_manually),
|
2023-08-16 10:47:25 +03:00
|
|
|
onPressed: () async {
|
2024-01-05 13:16:10 +03:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
await withContext((context) async {
|
|
|
|
await showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => OathAddAccountPage(
|
|
|
|
widget.devicePath,
|
|
|
|
widget.state,
|
|
|
|
credentials: credentials,
|
|
|
|
),
|
2023-08-18 12:34:15 +03:00
|
|
|
);
|
2024-01-05 13:16:10 +03:00
|
|
|
});
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
]
|
|
|
|
.map((e) => Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
|
|
child: e,
|
|
|
|
))
|
|
|
|
.toList(),
|
2023-08-16 10:47:25 +03:00
|
|
|
),
|
2024-01-05 13:16:10 +03:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2023-08-16 10:47:25 +03:00
|
|
|
}
|
|
|
|
}
|