encrypt_secret_screen.dart 4.8 KB

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