123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import 'package:appflowy/generated/locale_keys.g.dart';
- import 'package:appflowy/startup/startup.dart';
- import 'package:appflowy/user/presentation/sign_in_screen.dart';
- import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
- import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
- import 'package:easy_localization/easy_localization.dart';
- import 'package:flowy_infra_ui/flowy_infra_ui.dart';
- import 'package:flowy_infra_ui/widget/buttons/secondary_button.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_bloc/flutter_bloc.dart';
- import '../application/encrypt_secret_bloc.dart';
- class EncryptSecretScreen extends StatefulWidget {
- final UserProfilePB user;
- const EncryptSecretScreen({required this.user, super.key});
- @override
- State<EncryptSecretScreen> createState() => _EncryptSecretScreenState();
- }
- class _EncryptSecretScreenState extends State<EncryptSecretScreen> {
- final TextEditingController _textEditingController = TextEditingController();
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: BlocProvider(
- create: (context) => EncryptSecretBloc(user: widget.user),
- child: MultiBlocListener(
- listeners: [
- BlocListener<EncryptSecretBloc, EncryptSecretState>(
- listenWhen: (previous, current) =>
- previous.isSignOut != current.isSignOut,
- listener: (context, state) async {
- if (state.isSignOut) {
- await runAppFlowy();
- }
- },
- ),
- BlocListener<EncryptSecretBloc, EncryptSecretState>(
- listenWhen: (previous, current) =>
- previous.successOrFail != current.successOrFail,
- listener: (context, state) async {
- state.successOrFail.fold(
- () {},
- (result) {
- result.fold(
- (unit) async {
- await runAppFlowy();
- },
- (error) {
- handleOpenWorkspaceError(context, error);
- },
- );
- },
- );
- },
- ),
- ],
- child: BlocBuilder<EncryptSecretBloc, EncryptSecretState>(
- builder: (context, state) {
- final indicator = state.loadingState?.when(
- loading: () => const Center(
- child: CircularProgressIndicator.adaptive(),
- ),
- finish: (result) => const SizedBox.shrink(),
- ) ??
- const SizedBox.shrink();
- return Center(
- child: SizedBox(
- width: 300,
- height: 160,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Opacity(
- opacity: 0.6,
- child: FlowyText.medium(
- "${LocaleKeys.settings_menu_inputEncryptPrompt.tr()} ${widget.user.email}",
- fontSize: 14,
- maxLines: 10,
- ),
- ),
- const VSpace(6),
- SizedBox(
- width: 300,
- child: FlowyTextField(
- controller: _textEditingController,
- hintText:
- LocaleKeys.settings_menu_inputTextFieldHint.tr(),
- onChanged: (p0) {},
- ),
- ),
- OkCancelButton(
- alignment: MainAxisAlignment.end,
- onOkPressed: () {
- context.read<EncryptSecretBloc>().add(
- EncryptSecretEvent.setEncryptSecret(
- _textEditingController.text,
- ),
- );
- },
- onCancelPressed: () {
- context.read<EncryptSecretBloc>().add(
- const EncryptSecretEvent.cancelInputSecret(),
- );
- },
- mode: TextButtonMode.normal,
- ),
- const VSpace(6),
- indicator,
- ],
- ),
- ),
- );
- },
- ),
- ),
- ),
- );
- }
- }
|