2023-03-22 11:38:18 +00:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-05-19 14:26:57 +00:00
|
|
|
import 'package:cubit_form/cubit_form.dart';
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
|
|
|
import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart';
|
|
|
|
import 'package:selfprivacy/logic/cubit/forms/setup/recovering/recovery_domain_form_cubit.dart';
|
2023-03-27 17:02:44 +00:00
|
|
|
import 'package:selfprivacy/ui/components/buttons/brand_button.dart';
|
2023-02-23 14:49:14 +00:00
|
|
|
import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart';
|
2022-06-10 15:15:43 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/root_route.dart';
|
2022-05-19 17:43:25 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/setup/recovering/recover_by_old_token.dart';
|
2022-05-19 14:26:57 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/setup/recovering/recover_by_recovery_key.dart';
|
|
|
|
import 'package:selfprivacy/ui/pages/setup/recovering/recover_by_new_device_key.dart';
|
2023-05-12 19:32:19 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/setup/recovering/recovery_confirm_dns.dart';
|
2022-05-20 22:56:50 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/setup/recovering/recovery_confirm_server.dart';
|
2022-11-17 07:14:34 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/setup/recovering/recovery_server_provider_connected.dart';
|
2022-05-19 14:26:57 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/setup/recovering/recovery_method_select.dart';
|
2022-06-10 15:15:43 +00:00
|
|
|
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
2022-05-19 14:26:57 +00:00
|
|
|
|
2023-03-22 11:38:18 +00:00
|
|
|
@RoutePage()
|
2022-05-19 14:26:57 +00:00
|
|
|
class RecoveryRouting extends StatelessWidget {
|
2022-10-26 16:26:09 +00:00
|
|
|
const RecoveryRouting({super.key});
|
2022-05-24 18:55:39 +00:00
|
|
|
|
2022-05-19 14:26:57 +00:00
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final serverInstallation = context.watch<ServerInstallationCubit>().state;
|
2022-05-19 14:26:57 +00:00
|
|
|
|
2022-05-24 18:55:39 +00:00
|
|
|
Widget currentPage = const SelectDomainToRecover();
|
2022-05-19 14:26:57 +00:00
|
|
|
|
|
|
|
if (serverInstallation is ServerInstallationRecovery) {
|
2022-05-20 22:56:50 +00:00
|
|
|
switch (serverInstallation.currentStep) {
|
2022-05-24 18:55:39 +00:00
|
|
|
case RecoveryStep.selecting:
|
2022-05-26 01:02:06 +00:00
|
|
|
if (serverInstallation.recoveryCapabilities ==
|
|
|
|
ServerRecoveryCapabilities.loginTokens) {
|
2022-05-24 18:55:39 +00:00
|
|
|
currentPage = const RecoveryMethodSelect();
|
|
|
|
}
|
2022-05-26 01:02:06 +00:00
|
|
|
if (serverInstallation.recoveryCapabilities ==
|
|
|
|
ServerRecoveryCapabilities.legacy) {
|
|
|
|
currentPage = const RecoveryFallbackMethodSelect();
|
|
|
|
}
|
2022-05-19 14:26:57 +00:00
|
|
|
break;
|
2022-05-24 18:55:39 +00:00
|
|
|
case RecoveryStep.recoveryKey:
|
|
|
|
currentPage = const RecoverByRecoveryKey();
|
2022-05-19 14:26:57 +00:00
|
|
|
break;
|
2022-05-24 18:55:39 +00:00
|
|
|
case RecoveryStep.newDeviceKey:
|
2022-05-25 12:21:56 +00:00
|
|
|
currentPage = const RecoverByNewDeviceKeyInstruction();
|
2022-05-19 14:26:57 +00:00
|
|
|
break;
|
2022-05-24 18:55:39 +00:00
|
|
|
case RecoveryStep.oldToken:
|
2022-05-25 12:21:56 +00:00
|
|
|
currentPage = const RecoverByOldToken();
|
2022-05-19 14:26:57 +00:00
|
|
|
break;
|
2022-10-11 20:11:13 +00:00
|
|
|
case RecoveryStep.serverProviderToken:
|
2022-11-17 07:14:34 +00:00
|
|
|
currentPage = const RecoveryServerProviderConnected();
|
2022-05-19 14:26:57 +00:00
|
|
|
break;
|
2022-05-24 18:55:39 +00:00
|
|
|
case RecoveryStep.serverSelection:
|
|
|
|
currentPage = const RecoveryConfirmServer();
|
2022-05-19 17:43:25 +00:00
|
|
|
break;
|
2023-05-12 19:32:19 +00:00
|
|
|
case RecoveryStep.dnsProviderToken:
|
|
|
|
currentPage = const RecoveryConfirmDns();
|
2022-05-19 14:26:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 14:30:35 +00:00
|
|
|
return BlocListener<ServerInstallationCubit, ServerInstallationState>(
|
2022-06-05 22:40:34 +00:00
|
|
|
listener: (final context, final state) {
|
2022-05-31 14:30:35 +00:00
|
|
|
if (state is ServerInstallationFinished) {
|
2022-06-05 22:40:34 +00:00
|
|
|
Navigator.of(context).popUntil((final route) => route.isFirst);
|
2022-05-31 14:30:35 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
child: AnimatedSwitcher(
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
child: currentPage,
|
|
|
|
),
|
2022-05-19 14:26:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SelectDomainToRecover extends StatelessWidget {
|
2022-10-26 16:26:09 +00:00
|
|
|
const SelectDomainToRecover({super.key});
|
2022-05-24 18:55:39 +00:00
|
|
|
|
2022-05-19 14:26:57 +00:00
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final serverInstallation = context.watch<ServerInstallationCubit>();
|
2022-05-19 14:26:57 +00:00
|
|
|
|
|
|
|
return BlocProvider(
|
2022-06-05 22:40:34 +00:00
|
|
|
create: (final context) => RecoveryDomainFormCubit(
|
|
|
|
serverInstallation,
|
|
|
|
FieldCubitFactory(context),
|
|
|
|
),
|
2022-05-19 14:26:57 +00:00
|
|
|
child: Builder(
|
2022-06-05 22:40:34 +00:00
|
|
|
builder: (final context) {
|
|
|
|
final formCubitState = context.watch<RecoveryDomainFormCubit>().state;
|
2022-05-19 14:26:57 +00:00
|
|
|
|
|
|
|
return BlocListener<ServerInstallationCubit, ServerInstallationState>(
|
2022-06-05 22:40:34 +00:00
|
|
|
listener: (final context, final state) {
|
2022-05-19 14:26:57 +00:00
|
|
|
if (state is ServerInstallationRecovery) {
|
2022-05-24 18:55:39 +00:00
|
|
|
if (state.currentStep == RecoveryStep.selecting) {
|
2022-05-19 14:26:57 +00:00
|
|
|
if (state.recoveryCapabilities ==
|
|
|
|
ServerRecoveryCapabilities.none) {
|
|
|
|
context
|
|
|
|
.read<RecoveryDomainFormCubit>()
|
2022-05-24 18:55:39 +00:00
|
|
|
.setCustomError('recovering.domain_recover_error'.tr());
|
2022-05-19 14:26:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: BrandHeroScreen(
|
2022-05-24 18:55:39 +00:00
|
|
|
heroTitle: 'recovering.recovery_main_header'.tr(),
|
|
|
|
heroSubtitle: 'recovering.domain_recovery_description'.tr(),
|
2022-05-19 14:26:57 +00:00
|
|
|
hasBackButton: true,
|
|
|
|
hasFlashButton: false,
|
2023-04-04 14:31:35 +00:00
|
|
|
ignoreBreakpoints: true,
|
2022-06-10 15:15:43 +00:00
|
|
|
onBackButtonPressed: () {
|
|
|
|
Navigator.of(context).pushAndRemoveUntil(
|
|
|
|
materialRoute(const RootPage()),
|
|
|
|
(final predicate) => false,
|
|
|
|
);
|
|
|
|
},
|
2022-05-19 14:26:57 +00:00
|
|
|
children: [
|
|
|
|
CubitFormTextField(
|
2023-08-11 02:21:45 +00:00
|
|
|
autofocus: true,
|
2022-05-19 14:26:57 +00:00
|
|
|
formFieldCubit:
|
|
|
|
context.read<RecoveryDomainFormCubit>().serverDomainField,
|
|
|
|
decoration: InputDecoration(
|
2022-05-24 18:55:39 +00:00
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
labelText: 'recovering.domain_recover_placeholder'.tr(),
|
2022-05-19 14:26:57 +00:00
|
|
|
),
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 16),
|
2023-02-05 13:24:37 +00:00
|
|
|
BrandButton.filled(
|
2022-05-19 14:26:57 +00:00
|
|
|
onPressed: formCubitState.isSubmitting
|
|
|
|
? null
|
|
|
|
: () =>
|
|
|
|
context.read<RecoveryDomainFormCubit>().trySubmit(),
|
2023-02-05 13:24:37 +00:00
|
|
|
child: Text('basis.continue'.tr()),
|
2022-05-19 14:26:57 +00:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|