encrypt_secret_screen.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import 'package:appflowy/generated/locale_keys.g.dart';
  2. import 'package:appflowy/startup/startup.dart';
  3. import 'package:appflowy/user/presentation/sign_in_screen.dart';
  4. import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
  5. import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
  6. import 'package:easy_localization/easy_localization.dart';
  7. import 'package:flowy_infra_ui/flowy_infra_ui.dart';
  8. import 'package:flowy_infra_ui/widget/buttons/secondary_button.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:flutter_bloc/flutter_bloc.dart';
  11. import '../application/encrypt_secret_bloc.dart';
  12. class EncryptSecretScreen extends StatefulWidget {
  13. final UserProfilePB user;
  14. const EncryptSecretScreen({required this.user, super.key});
  15. @override
  16. State<EncryptSecretScreen> createState() => _EncryptSecretScreenState();
  17. }
  18. class _EncryptSecretScreenState extends State<EncryptSecretScreen> {
  19. final TextEditingController _textEditingController = TextEditingController();
  20. @override
  21. Widget build(BuildContext context) {
  22. return Scaffold(
  23. body: BlocProvider(
  24. create: (context) => EncryptSecretBloc(user: widget.user),
  25. child: MultiBlocListener(
  26. listeners: [
  27. BlocListener<EncryptSecretBloc, EncryptSecretState>(
  28. listenWhen: (previous, current) =>
  29. previous.isSignOut != current.isSignOut,
  30. listener: (context, state) async {
  31. if (state.isSignOut) {
  32. await runAppFlowy();
  33. }
  34. },
  35. ),
  36. BlocListener<EncryptSecretBloc, EncryptSecretState>(
  37. listenWhen: (previous, current) =>
  38. previous.successOrFail != current.successOrFail,
  39. listener: (context, state) async {
  40. state.successOrFail.fold(
  41. () {},
  42. (result) {
  43. result.fold(
  44. (unit) async {
  45. await runAppFlowy();
  46. },
  47. (error) {
  48. handleOpenWorkspaceError(context, error);
  49. },
  50. );
  51. },
  52. );
  53. },
  54. ),
  55. ],
  56. child: BlocBuilder<EncryptSecretBloc, EncryptSecretState>(
  57. builder: (context, state) {
  58. final indicator = state.loadingState?.when(
  59. loading: () => const Center(
  60. child: CircularProgressIndicator.adaptive(),
  61. ),
  62. finish: (result) => const SizedBox.shrink(),
  63. ) ??
  64. const SizedBox.shrink();
  65. return Center(
  66. child: SizedBox(
  67. width: 300,
  68. height: 160,
  69. child: Column(
  70. crossAxisAlignment: CrossAxisAlignment.start,
  71. children: [
  72. Opacity(
  73. opacity: 0.6,
  74. child: FlowyText.medium(
  75. "${LocaleKeys.settings_menu_inputEncryptPrompt.tr()} ${widget.user.email}",
  76. fontSize: 14,
  77. maxLines: 10,
  78. ),
  79. ),
  80. const VSpace(6),
  81. SizedBox(
  82. width: 300,
  83. child: FlowyTextField(
  84. controller: _textEditingController,
  85. hintText:
  86. LocaleKeys.settings_menu_inputTextFieldHint.tr(),
  87. onChanged: (p0) {},
  88. ),
  89. ),
  90. OkCancelButton(
  91. alignment: MainAxisAlignment.end,
  92. onOkPressed: () {
  93. context.read<EncryptSecretBloc>().add(
  94. EncryptSecretEvent.setEncryptSecret(
  95. _textEditingController.text,
  96. ),
  97. );
  98. },
  99. onCancelPressed: () {
  100. context.read<EncryptSecretBloc>().add(
  101. const EncryptSecretEvent.cancelInputSecret(),
  102. );
  103. },
  104. mode: TextButtonMode.normal,
  105. ),
  106. const VSpace(6),
  107. indicator,
  108. ],
  109. ),
  110. ),
  111. );
  112. },
  113. ),
  114. ),
  115. ),
  116. );
  117. }
  118. }