2022-05-17 13:29:04 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2022-05-17 23:18:26 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/forms/setup/recovering/recovery_device_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-05-19 14:26:57 +00:00
|
|
|
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
|
|
|
import 'package:cubit_form/cubit_form.dart';
|
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
|
|
|
import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart';
|
|
|
|
|
|
|
|
class RecoverByNewDeviceKeyInstruction extends StatelessWidget {
|
2022-10-26 16:26:09 +00:00
|
|
|
const RecoverByNewDeviceKeyInstruction({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) => BrandHeroScreen(
|
|
|
|
heroTitle: 'recovering.recovery_main_header'.tr(),
|
|
|
|
heroSubtitle: 'recovering.method_device_description'.tr(),
|
|
|
|
hasBackButton: true,
|
|
|
|
hasFlashButton: false,
|
2023-04-04 14:31:35 +00:00
|
|
|
ignoreBreakpoints: true,
|
2022-06-09 21:13:06 +00:00
|
|
|
onBackButtonPressed:
|
|
|
|
context.read<ServerInstallationCubit>().revertRecoveryStep,
|
2022-06-05 22:40:34 +00:00
|
|
|
children: [
|
2023-02-05 13:24:37 +00:00
|
|
|
BrandButton.filled(
|
|
|
|
child: Text('recovering.method_device_button'.tr()),
|
2022-06-05 22:40:34 +00:00
|
|
|
onPressed: () => Navigator.of(context)
|
|
|
|
.push(materialRoute(const RecoverByNewDeviceKeyInput())),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
2022-05-19 14:26:57 +00:00
|
|
|
}
|
2022-05-17 13:29:04 +00:00
|
|
|
|
2022-05-19 14:26:57 +00:00
|
|
|
class RecoverByNewDeviceKeyInput extends StatelessWidget {
|
2022-10-26 16:26:09 +00:00
|
|
|
const RecoverByNewDeviceKeyInput({super.key});
|
2022-05-24 18:55:39 +00:00
|
|
|
|
2022-05-17 13:29:04 +00:00
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final ServerInstallationCubit appConfig =
|
|
|
|
context.watch<ServerInstallationCubit>();
|
2022-05-17 23:18:26 +00:00
|
|
|
|
|
|
|
return BlocProvider(
|
2022-06-05 22:40:34 +00:00
|
|
|
create: (final BuildContext context) => RecoveryDeviceFormCubit(
|
2022-05-20 22:56:50 +00:00
|
|
|
appConfig,
|
|
|
|
FieldCubitFactory(context),
|
|
|
|
ServerRecoveryMethods.newDeviceKey,
|
|
|
|
),
|
2022-05-24 17:45:13 +00:00
|
|
|
child: BlocListener<ServerInstallationCubit, ServerInstallationState>(
|
2022-06-05 22:40:34 +00:00
|
|
|
listener:
|
|
|
|
(final BuildContext context, final ServerInstallationState state) {
|
2022-05-24 17:45:13 +00:00
|
|
|
if (state is ServerInstallationRecovery &&
|
2022-05-24 18:55:39 +00:00
|
|
|
state.currentStep != RecoveryStep.newDeviceKey) {
|
2022-05-24 17:45:13 +00:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Builder(
|
2022-06-05 22:40:34 +00:00
|
|
|
builder: (final BuildContext context) {
|
|
|
|
final FormCubitState formCubitState =
|
|
|
|
context.watch<RecoveryDeviceFormCubit>().state;
|
2022-05-17 23:18:26 +00:00
|
|
|
|
2022-05-24 17:45:13 +00:00
|
|
|
return BrandHeroScreen(
|
2022-05-24 18:55:39 +00:00
|
|
|
heroTitle: 'recovering.recovery_main_header'.tr(),
|
|
|
|
heroSubtitle: 'recovering.method_device_input_description'.tr(),
|
2022-05-24 17:45:13 +00:00
|
|
|
hasBackButton: true,
|
|
|
|
hasFlashButton: false,
|
2023-04-04 14:31:35 +00:00
|
|
|
ignoreBreakpoints: true,
|
2022-05-24 17:45:13 +00:00
|
|
|
children: [
|
|
|
|
CubitFormTextField(
|
2023-08-11 02:21:45 +00:00
|
|
|
autofocus: true,
|
2022-05-24 17:45:13 +00:00
|
|
|
formFieldCubit:
|
|
|
|
context.read<RecoveryDeviceFormCubit>().tokenField,
|
|
|
|
decoration: InputDecoration(
|
2022-05-24 18:55:39 +00:00
|
|
|
border: const OutlineInputBorder(),
|
2022-05-24 17:45:13 +00:00
|
|
|
labelText:
|
2022-05-24 18:55:39 +00:00
|
|
|
'recovering.method_device_input_placeholder'.tr(),
|
2022-05-24 17:45:13 +00:00
|
|
|
),
|
2022-05-17 23:18:26 +00:00
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 16),
|
2022-05-24 17:45:13 +00:00
|
|
|
FilledButton(
|
|
|
|
onPressed: formCubitState.isSubmitting
|
|
|
|
? null
|
|
|
|
: () =>
|
|
|
|
context.read<RecoveryDeviceFormCubit>().trySubmit(),
|
2023-02-05 13:24:37 +00:00
|
|
|
child: Text('basis.continue'.tr()),
|
2022-05-24 17:45:13 +00:00
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-05-17 23:18:26 +00:00
|
|
|
),
|
2022-05-17 13:29:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|