settings_dialog.dart 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import 'package:appflowy/startup/startup.dart';
  2. import 'package:appflowy/generated/locale_keys.g.dart';
  3. import 'package:appflowy/workspace/presentation/settings/widgets/setting_supabase_view.dart';
  4. import 'package:appflowy/workspace/presentation/settings/widgets/settings_appearance_view.dart';
  5. import 'package:appflowy/workspace/presentation/settings/widgets/settings_file_system_view.dart';
  6. import 'package:appflowy/workspace/presentation/settings/widgets/settings_language_view.dart';
  7. import 'package:appflowy/workspace/presentation/settings/widgets/settings_user_view.dart';
  8. import 'package:appflowy/workspace/presentation/settings/widgets/settings_menu.dart';
  9. import 'package:appflowy/workspace/application/settings/settings_dialog_bloc.dart';
  10. import 'package:flowy_infra_ui/flowy_infra_ui.dart';
  11. import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
  12. import 'package:easy_localization/easy_localization.dart';
  13. import 'package:flutter/material.dart';
  14. import 'package:flutter_bloc/flutter_bloc.dart';
  15. const _dialogHorizontalPadding = EdgeInsets.symmetric(horizontal: 12);
  16. const _contentInsetPadding = EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 16.0);
  17. class SettingsDialog extends StatelessWidget {
  18. final UserProfilePB user;
  19. SettingsDialog(this.user, {Key? key}) : super(key: ValueKey(user.id));
  20. @override
  21. Widget build(BuildContext context) {
  22. return BlocProvider<SettingsDialogBloc>(
  23. create: (context) => getIt<SettingsDialogBloc>(param1: user)
  24. ..add(const SettingsDialogEvent.initial()),
  25. child: BlocBuilder<SettingsDialogBloc, SettingsDialogState>(
  26. builder: (context, state) => FlowyDialog(
  27. title: Padding(
  28. padding: _dialogHorizontalPadding + _contentInsetPadding,
  29. child: FlowyText(
  30. LocaleKeys.settings_title.tr(),
  31. fontSize: 20,
  32. fontWeight: FontWeight.w700,
  33. color: Theme.of(context).colorScheme.tertiary,
  34. ),
  35. ),
  36. child: ScaffoldMessenger(
  37. child: Scaffold(
  38. backgroundColor: Colors.transparent,
  39. body: Padding(
  40. padding: _dialogHorizontalPadding,
  41. child: Row(
  42. crossAxisAlignment: CrossAxisAlignment.start,
  43. children: [
  44. SizedBox(
  45. width: 200,
  46. child: SettingsMenu(
  47. changeSelectedPage: (index) {
  48. context
  49. .read<SettingsDialogBloc>()
  50. .add(SettingsDialogEvent.setSelectedPage(index));
  51. },
  52. currentPage:
  53. context.read<SettingsDialogBloc>().state.page,
  54. ),
  55. ),
  56. VerticalDivider(
  57. color: Theme.of(context).dividerColor,
  58. ),
  59. const SizedBox(width: 10),
  60. Expanded(
  61. child: getSettingsView(
  62. context.read<SettingsDialogBloc>().state.page,
  63. context.read<SettingsDialogBloc>().state.userProfile,
  64. ),
  65. )
  66. ],
  67. ),
  68. ),
  69. ),
  70. ),
  71. ),
  72. ),
  73. );
  74. }
  75. Widget getSettingsView(SettingsPage page, UserProfilePB user) {
  76. switch (page) {
  77. case SettingsPage.appearance:
  78. return const SettingsAppearanceView();
  79. case SettingsPage.language:
  80. return const SettingsLanguageView();
  81. case SettingsPage.files:
  82. return const SettingsFileSystemView();
  83. case SettingsPage.user:
  84. return SettingsUserView(user);
  85. case SettingsPage.supabaseSetting:
  86. return const SupabaseSettingView();
  87. default:
  88. return Container();
  89. }
  90. }
  91. }