settings_dialog.dart 3.6 KB

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