2022-05-19 17:43:25 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2022-05-20 22:56:50 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/server_basic_info.dart';
|
2022-05-24 18:55:39 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_button/filled_button.dart';
|
2022-05-20 22:56:50 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
2022-09-15 16:57:26 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_cards/filled_card.dart';
|
2022-05-19 17:43:25 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
|
|
|
|
|
2022-05-20 22:56:50 +00:00
|
|
|
class RecoveryConfirmServer extends StatefulWidget {
|
2022-06-05 22:40:34 +00:00
|
|
|
const RecoveryConfirmServer({final super.key});
|
2022-05-20 22:56:50 +00:00
|
|
|
|
|
|
|
@override
|
2022-05-25 12:21:56 +00:00
|
|
|
State<RecoveryConfirmServer> createState() => _RecoveryConfirmServerState();
|
2022-05-20 22:56:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _RecoveryConfirmServerState extends State<RecoveryConfirmServer> {
|
|
|
|
bool _isExtended = false;
|
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
bool _isServerFound(final List<ServerBasicInfoWithValidators> servers) =>
|
|
|
|
servers
|
|
|
|
.where((final server) => server.isIpValid && server.isReverseDnsValid)
|
|
|
|
.length ==
|
|
|
|
1;
|
2022-05-20 22:56:50 +00:00
|
|
|
|
|
|
|
ServerBasicInfoWithValidators _firstValidServer(
|
2022-06-05 22:40:34 +00:00
|
|
|
final List<ServerBasicInfoWithValidators> servers,
|
|
|
|
) =>
|
|
|
|
servers
|
|
|
|
.where((final server) => server.isIpValid && server.isReverseDnsValid)
|
|
|
|
.first;
|
2022-05-20 22:56:50 +00:00
|
|
|
|
2022-05-19 17:43:25 +00:00
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) => BrandHeroScreen(
|
|
|
|
heroTitle: _isExtended
|
|
|
|
? 'recovering.choose_server'.tr()
|
|
|
|
: 'recovering.confirm_server'.tr(),
|
|
|
|
heroSubtitle: _isExtended
|
|
|
|
? 'recovering.choose_server_description'.tr()
|
|
|
|
: 'recovering.confirm_server_description'.tr(),
|
|
|
|
hasBackButton: true,
|
2022-06-15 04:51:32 +00:00
|
|
|
onBackButtonPressed: () {
|
|
|
|
Navigator.of(context).popUntil((final route) => route.isFirst);
|
|
|
|
},
|
2022-06-05 22:40:34 +00:00
|
|
|
hasFlashButton: false,
|
|
|
|
children: [
|
|
|
|
FutureBuilder<List<ServerBasicInfoWithValidators>>(
|
|
|
|
future: context
|
|
|
|
.read<ServerInstallationCubit>()
|
|
|
|
.getServersOnHetznerAccount(),
|
|
|
|
builder: (final context, final snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
final servers = snapshot.data;
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
if (servers != null && servers.isNotEmpty)
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
if (servers.length == 1 ||
|
|
|
|
(!_isExtended && _isServerFound(servers)))
|
|
|
|
confirmServer(
|
|
|
|
context,
|
|
|
|
_firstValidServer(servers),
|
|
|
|
servers.length > 1,
|
|
|
|
),
|
|
|
|
if (servers.length > 1 &&
|
|
|
|
(_isExtended || !_isServerFound(servers)))
|
|
|
|
chooseServer(context, servers),
|
|
|
|
],
|
2022-05-20 22:56:50 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
if (servers?.isEmpty ?? true)
|
|
|
|
Center(
|
|
|
|
child: Text(
|
|
|
|
'recovering.no_servers'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headline6,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
2022-05-20 22:56:50 +00:00
|
|
|
|
2022-05-25 12:21:56 +00:00
|
|
|
Widget confirmServer(
|
2022-06-05 22:40:34 +00:00
|
|
|
final BuildContext context,
|
|
|
|
final ServerBasicInfoWithValidators server,
|
|
|
|
final bool showMoreServersButton,
|
|
|
|
) =>
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
serverCard(
|
|
|
|
context: context,
|
|
|
|
server: server,
|
2022-05-19 17:43:25 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
const SizedBox(height: 16),
|
|
|
|
FilledButton(
|
|
|
|
title: 'recovering.confirm_server_accept'.tr(),
|
|
|
|
onPressed: () => _showConfirmationDialog(context, server),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
if (showMoreServersButton)
|
|
|
|
BrandButton.text(
|
|
|
|
title: 'recovering.confirm_server_decline'.tr(),
|
|
|
|
onPressed: () => setState(() => _isExtended = true),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2022-05-20 22:56:50 +00:00
|
|
|
|
2022-05-25 12:21:56 +00:00
|
|
|
Widget chooseServer(
|
2022-06-05 22:40:34 +00:00
|
|
|
final BuildContext context,
|
|
|
|
final List<ServerBasicInfoWithValidators> servers,
|
|
|
|
) =>
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
for (final server in servers)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
|
|
child: serverCard(
|
|
|
|
context: context,
|
|
|
|
server: server,
|
|
|
|
onTap: () => _showConfirmationDialog(context, server),
|
|
|
|
),
|
2022-05-20 22:56:50 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
],
|
|
|
|
);
|
2022-05-20 22:56:50 +00:00
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget serverCard({
|
|
|
|
required final BuildContext context,
|
|
|
|
required final ServerBasicInfoWithValidators server,
|
|
|
|
final VoidCallback? onTap,
|
|
|
|
}) =>
|
2022-09-15 16:57:26 +00:00
|
|
|
FilledCard(
|
2022-06-05 22:40:34 +00:00
|
|
|
child: ListTile(
|
|
|
|
contentPadding:
|
|
|
|
const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
|
|
|
|
onTap: onTap,
|
|
|
|
title: Text(
|
|
|
|
server.name,
|
|
|
|
style: Theme.of(context).textTheme.titleMedium!.copyWith(
|
2022-05-30 13:55:52 +00:00
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
|
|
|
leading: Icon(
|
|
|
|
Icons.dns_outlined,
|
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
),
|
|
|
|
subtitle: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
server.isReverseDnsValid ? Icons.check : Icons.close,
|
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
2022-05-30 13:55:52 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
const SizedBox(width: 8),
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
'rDNS: ${server.reverseDns}',
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
),
|
|
|
|
),
|
2022-05-30 13:55:52 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
server.isIpValid ? Icons.check : Icons.close,
|
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
'IP: ${server.ip}',
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-05-20 22:56:50 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
);
|
2022-05-20 22:56:50 +00:00
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
Future _showConfirmationDialog(
|
|
|
|
final BuildContext context,
|
|
|
|
final ServerBasicInfoWithValidators server,
|
|
|
|
) =>
|
2022-05-20 22:56:50 +00:00
|
|
|
showDialog(
|
|
|
|
context: context,
|
2022-06-05 22:40:34 +00:00
|
|
|
builder: (final context) => AlertDialog(
|
|
|
|
title: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.warning_amber_outlined),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'recovering.modal_confirmation_title'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
content: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(
|
|
|
|
'recovering.modal_confirmation_description'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
const Divider(),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
Text(
|
|
|
|
server.name,
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
textAlign: TextAlign.start,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
IsValidStringDisplay(
|
|
|
|
isValid: server.isReverseDnsValid,
|
|
|
|
textIfValid: 'recovering.modal_confirmation_dns_valid'.tr(),
|
|
|
|
textIfInvalid: 'recovering.modal_confirmation_dns_invalid'.tr(),
|
2022-05-24 17:45:13 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
const SizedBox(height: 8),
|
|
|
|
IsValidStringDisplay(
|
|
|
|
isValid: server.isIpValid,
|
|
|
|
textIfValid: 'recovering.modal_confirmation_ip_valid'.tr(),
|
|
|
|
textIfInvalid: 'recovering.modal_confirmation_ip_invalid'.tr(),
|
2022-05-20 22:56:50 +00:00
|
|
|
),
|
|
|
|
],
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
child: Text('modals.no'.tr()),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
child: Text('modals.yes'.tr()),
|
|
|
|
onPressed: () {
|
|
|
|
context.read<ServerInstallationCubit>().setServerId(server);
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-05-20 22:56:50 +00:00
|
|
|
);
|
2022-05-19 17:43:25 +00:00
|
|
|
}
|
2022-05-30 13:55:52 +00:00
|
|
|
|
|
|
|
class IsValidStringDisplay extends StatelessWidget {
|
|
|
|
const IsValidStringDisplay({
|
|
|
|
required this.isValid,
|
|
|
|
required this.textIfValid,
|
|
|
|
required this.textIfInvalid,
|
2022-06-05 22:40:34 +00:00
|
|
|
final super.key,
|
2022-06-05 19:36:32 +00:00
|
|
|
});
|
2022-05-30 13:55:52 +00:00
|
|
|
|
|
|
|
final bool isValid;
|
|
|
|
final String textIfValid;
|
|
|
|
final String textIfInvalid;
|
|
|
|
|
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) => Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
if (isValid)
|
|
|
|
Icon(Icons.check, color: Theme.of(context).colorScheme.onSurface)
|
|
|
|
else
|
|
|
|
Icon(Icons.close, color: Theme.of(context).colorScheme.error),
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
Expanded(
|
2022-05-30 23:06:08 +00:00
|
|
|
child: isValid
|
|
|
|
? Text(
|
|
|
|
textIfValid,
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Text(
|
|
|
|
textIfInvalid,
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.error,
|
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2022-05-30 13:55:52 +00:00
|
|
|
}
|