2023-07-25 19:43:28 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2023-07-20 21:35:13 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2024-01-29 13:54:09 +00:00
|
|
|
import 'package:selfprivacy/logic/bloc/backups/backups_bloc.dart';
|
|
|
|
import 'package:selfprivacy/logic/bloc/server_jobs/server_jobs_bloc.dart';
|
2024-01-31 10:57:12 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
2023-08-14 04:09:06 +00:00
|
|
|
import 'package:selfprivacy/ui/components/info_box/info_box.dart';
|
2023-09-07 21:25:13 +00:00
|
|
|
import 'package:selfprivacy/utils/platform_adapter.dart';
|
2023-07-20 21:35:13 +00:00
|
|
|
|
|
|
|
class CopyEncryptionKeyModal extends StatefulWidget {
|
|
|
|
const CopyEncryptionKeyModal({
|
|
|
|
required this.scrollController,
|
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
final ScrollController scrollController;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<CopyEncryptionKeyModal> createState() => _CopyEncryptionKeyModalState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CopyEncryptionKeyModalState extends State<CopyEncryptionKeyModal> {
|
|
|
|
bool isKeyVisible = false;
|
2023-07-25 19:43:28 +00:00
|
|
|
bool copiedToClipboard = false;
|
|
|
|
Timer? copyToClipboardTimer;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
copyToClipboardTimer?.cancel();
|
|
|
|
super.dispose();
|
|
|
|
}
|
2023-07-25 19:25:08 +00:00
|
|
|
|
2023-07-20 21:35:13 +00:00
|
|
|
@override
|
|
|
|
Widget build(final BuildContext context) {
|
2023-08-14 04:09:06 +00:00
|
|
|
final String? encryptionKey =
|
2024-01-29 13:54:09 +00:00
|
|
|
context.watch<BackupsBloc>().state.backblazeBucket?.encryptionKey;
|
2023-08-14 04:09:06 +00:00
|
|
|
if (encryptionKey == null) {
|
|
|
|
return ListView(
|
|
|
|
controller: widget.scrollController,
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
children: [
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'backup.backups_encryption_key'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
InfoBox(
|
|
|
|
text: 'backup.backups_encryption_key_not_found'.tr(),
|
|
|
|
isWarning: true,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2023-07-20 21:35:13 +00:00
|
|
|
return ListView(
|
|
|
|
controller: widget.scrollController,
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
children: [
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'backup.backups_encryption_key'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
2023-07-25 19:25:08 +00:00
|
|
|
Text(
|
|
|
|
'backup.backups_encryption_key_description'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
textAlign: TextAlign.center,
|
2023-07-20 21:35:13 +00:00
|
|
|
),
|
2023-07-25 19:25:08 +00:00
|
|
|
const SizedBox(height: 8),
|
|
|
|
Container(
|
2023-08-06 23:32:05 +00:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
|
|
|
color: Theme.of(context).colorScheme.surfaceVariant,
|
|
|
|
),
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
SelectableText(
|
|
|
|
encryptionKey,
|
|
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Positioned.fill(
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
setState(
|
|
|
|
() {
|
|
|
|
isKeyVisible = !isKeyVisible;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: AnimatedOpacity(
|
|
|
|
duration: const Duration(milliseconds: 200),
|
|
|
|
opacity: isKeyVisible ? 0 : 1,
|
|
|
|
child: Container(
|
|
|
|
color: Theme.of(context).colorScheme.surfaceVariant,
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.visibility_outlined),
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
Text(
|
|
|
|
'backup.backups_encryption_key_show'.tr(),
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyMedium
|
|
|
|
?.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.onSurfaceVariant,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2023-07-20 21:35:13 +00:00
|
|
|
),
|
2023-07-25 19:25:08 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-08-06 23:32:05 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2023-07-25 19:25:08 +00:00
|
|
|
const SizedBox(height: 8),
|
|
|
|
FilledButton.icon(
|
|
|
|
onPressed: () {
|
2023-07-25 19:43:28 +00:00
|
|
|
setState(
|
|
|
|
() {
|
|
|
|
copiedToClipboard = true;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
setState(() {
|
|
|
|
copyToClipboardTimer?.cancel();
|
|
|
|
copyToClipboardTimer = Timer(
|
|
|
|
const Duration(seconds: 5),
|
|
|
|
() {
|
|
|
|
setState(() {
|
|
|
|
copiedToClipboard = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2023-09-07 21:25:13 +00:00
|
|
|
PlatformAdapter.setClipboard(encryptionKey);
|
2023-07-25 19:25:08 +00:00
|
|
|
},
|
|
|
|
icon: const Icon(Icons.copy_all_outlined),
|
2023-07-25 19:43:28 +00:00
|
|
|
label: Text(
|
|
|
|
copiedToClipboard
|
|
|
|
? 'basis.copied_to_clipboard'.tr()
|
|
|
|
: 'backup.backups_encryption_key_copy'.tr(),
|
|
|
|
),
|
2023-07-20 21:35:13 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|