selfprivacy.org.app/lib/ui/pages/setup/recovering/recover_by_old_token.dart

97 lines
3.4 KiB
Dart
Raw Normal View History

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
2022-05-18 02:18:26 +03:00
import 'package:selfprivacy/logic/cubit/forms/setup/recovering/recovery_device_form_cubit.dart';
2022-05-24 21:55:39 +03:00
import 'package:selfprivacy/ui/components/brand_button/filled_button.dart';
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
import 'package:selfprivacy/ui/components/brand_md/brand_md.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 RecoverByOldTokenInstruction extends StatelessWidget {
@override
const RecoverByOldTokenInstruction(
{Key? key, required this.instructionFilename})
: super(key: key);
2022-05-24 21:55:39 +03:00
@override
Widget build(BuildContext context) {
return BlocListener<ServerInstallationCubit, ServerInstallationState>(
listener: (context, state) {
if (state is ServerInstallationRecovery &&
2022-05-24 21:55:39 +03:00
state.currentStep != RecoveryStep.selecting) {
Navigator.of(context).pop();
Navigator.of(context).pop();
}
},
child: BrandHeroScreen(
2022-05-24 21:55:39 +03:00
heroTitle: 'recovering.recovery_main_header'.tr(),
hasBackButton: true,
hasFlashButton: false,
onBackButtonPressed: () =>
context.read<ServerInstallationCubit>().revertRecoveryStep(),
children: [
BrandMarkdown(
fileName: instructionFilename,
),
2022-05-24 21:55:39 +03:00
const SizedBox(height: 18),
FilledButton(
2022-05-24 21:55:39 +03:00
title: 'recovering.method_device_button'.tr(),
onPressed: () => context
.read<ServerInstallationCubit>()
.selectRecoveryMethod(ServerRecoveryMethods.oldToken),
)
],
),
);
}
final String instructionFilename;
}
class RecoverByOldToken extends StatelessWidget {
2022-05-24 21:55:39 +03:00
const RecoverByOldToken({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
2022-05-18 02:18:26 +03:00
var appConfig = context.watch<ServerInstallationCubit>();
return BlocProvider(
create: (context) => RecoveryDeviceFormCubit(
appConfig,
FieldCubitFactory(context),
ServerRecoveryMethods.oldToken,
),
2022-05-18 02:18:26 +03:00
child: Builder(
builder: (context) {
var formCubitState = context.watch<RecoveryDeviceFormCubit>().state;
return BrandHeroScreen(
2022-05-24 21:55:39 +03:00
heroTitle: 'recovering.recovery_main_header'.tr(),
heroSubtitle: 'recovering.method_device_input_description'.tr(),
2022-05-18 02:18:26 +03:00
hasBackButton: true,
hasFlashButton: false,
children: [
CubitFormTextField(
formFieldCubit:
context.read<RecoveryDeviceFormCubit>().tokenField,
decoration: InputDecoration(
2022-05-24 21:55:39 +03:00
border: const OutlineInputBorder(),
labelText: 'recovering.method_device_input_placeholder'.tr(),
2022-05-18 02:18:26 +03:00
),
),
2022-05-24 21:55:39 +03:00
const SizedBox(height: 18),
2022-05-18 02:18:26 +03:00
FilledButton(
2022-05-24 21:55:39 +03:00
title: 'more.continue'.tr(),
2022-05-18 02:18:26 +03:00
onPressed: formCubitState.isSubmitting
? null
: () => context.read<RecoveryDeviceFormCubit>().trySubmit(),
)
],
);
},
),
);
}
}