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';
|
2022-05-24 18:55:39 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_button/filled_button.dart';
|
2022-05-17 13:29:04 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_hero_screen/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-05-24 18:55:39 +00:00
|
|
|
const RecoverByNewDeviceKeyInstruction({Key? key}) : super(key: key);
|
|
|
|
|
2022-05-19 14:26:57 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return BrandHeroScreen(
|
2022-05-24 18:55:39 +00:00
|
|
|
heroTitle: 'recovering.recovery_main_header'.tr(),
|
|
|
|
heroSubtitle: 'recovering.method_device_description'.tr(),
|
2022-05-19 14:26:57 +00:00
|
|
|
hasBackButton: true,
|
|
|
|
hasFlashButton: false,
|
|
|
|
onBackButtonPressed: () =>
|
|
|
|
context.read<ServerInstallationCubit>().revertRecoveryStep(),
|
|
|
|
children: [
|
|
|
|
FilledButton(
|
2022-05-24 18:55:39 +00:00
|
|
|
title: 'recovering.method_device_button'.tr(),
|
2022-05-19 14:26:57 +00:00
|
|
|
onPressed: () => Navigator.of(context)
|
2022-05-24 18:55:39 +00:00
|
|
|
.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-05-24 18:55:39 +00:00
|
|
|
const RecoverByNewDeviceKeyInput({Key? key}) : super(key: key);
|
|
|
|
|
2022-05-17 13:29:04 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-05-17 23:18:26 +00:00
|
|
|
var appConfig = context.watch<ServerInstallationCubit>();
|
|
|
|
|
|
|
|
return BlocProvider(
|
2022-05-20 22:56:50 +00:00
|
|
|
create: (context) => RecoveryDeviceFormCubit(
|
|
|
|
appConfig,
|
|
|
|
FieldCubitFactory(context),
|
|
|
|
ServerRecoveryMethods.newDeviceKey,
|
|
|
|
),
|
2022-05-24 17:45:13 +00:00
|
|
|
child: BlocListener<ServerInstallationCubit, ServerInstallationState>(
|
|
|
|
listener: (context, state) {
|
|
|
|
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(
|
|
|
|
builder: (context) {
|
|
|
|
var 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,
|
|
|
|
children: [
|
|
|
|
CubitFormTextField(
|
|
|
|
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(
|
2022-05-24 18:55:39 +00:00
|
|
|
title: 'more.continue'.tr(),
|
2022-05-24 17:45:13 +00:00
|
|
|
onPressed: formCubitState.isSubmitting
|
|
|
|
? null
|
|
|
|
: () =>
|
|
|
|
context.read<RecoveryDeviceFormCubit>().trySubmit(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-05-17 23:18:26 +00:00
|
|
|
),
|
2022-05-17 13:29:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|