editor_styles.dart 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import 'package:app_flowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart';
  2. import 'package:appflowy_editor/appflowy_editor.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:provider/provider.dart';
  5. EditorStyle customEditorTheme(BuildContext context) {
  6. final documentStyle = context.watch<DocumentAppearanceCubit>().state;
  7. var editorStyle = Theme.of(context).brightness == Brightness.dark
  8. ? EditorStyle.dark
  9. : EditorStyle.light;
  10. editorStyle = editorStyle.copyWith(
  11. padding: const EdgeInsets.symmetric(horizontal: 100, vertical: 28),
  12. textStyle: editorStyle.textStyle?.copyWith(
  13. fontFamily: 'poppins',
  14. fontSize: documentStyle.fontSize,
  15. ),
  16. placeholderTextStyle: editorStyle.placeholderTextStyle?.copyWith(
  17. fontFamily: 'poppins',
  18. fontSize: documentStyle.fontSize,
  19. ),
  20. bold: editorStyle.bold?.copyWith(
  21. fontWeight: FontWeight.w600,
  22. fontFamily: 'poppins-Bold',
  23. ),
  24. backgroundColor: Theme.of(context).colorScheme.surface,
  25. selectionMenuItemSelectedIconColor: Theme.of(context).colorScheme.primary,
  26. );
  27. return editorStyle;
  28. }
  29. Iterable<ThemeExtension<dynamic>> customPluginTheme(BuildContext context) {
  30. final documentStyle = context.watch<DocumentAppearanceCubit>().state;
  31. final baseFontSize = documentStyle.fontSize;
  32. const basePadding = 12.0;
  33. var headingPluginStyle = Theme.of(context).brightness == Brightness.dark
  34. ? HeadingPluginStyle.dark
  35. : HeadingPluginStyle.light;
  36. headingPluginStyle = headingPluginStyle.copyWith(
  37. textStyle: (EditorState editorState, Node node) {
  38. final headingToFontSize = {
  39. 'h1': baseFontSize + 12,
  40. 'h2': baseFontSize + 8,
  41. 'h3': baseFontSize + 4,
  42. 'h4': baseFontSize,
  43. 'h5': baseFontSize,
  44. 'h6': baseFontSize,
  45. };
  46. final fontSize =
  47. headingToFontSize[node.attributes.heading] ?? baseFontSize;
  48. return TextStyle(fontSize: fontSize, fontWeight: FontWeight.w600);
  49. },
  50. padding: (EditorState editorState, Node node) {
  51. final headingToPadding = {
  52. 'h1': basePadding + 6,
  53. 'h2': basePadding + 4,
  54. 'h3': basePadding + 2,
  55. 'h4': basePadding,
  56. 'h5': basePadding,
  57. 'h6': basePadding,
  58. };
  59. final padding = headingToPadding[node.attributes.heading] ?? basePadding;
  60. return EdgeInsets.only(bottom: padding);
  61. },
  62. );
  63. var numberListPluginStyle = Theme.of(context).brightness == Brightness.dark
  64. ? NumberListPluginStyle.dark
  65. : NumberListPluginStyle.light;
  66. numberListPluginStyle = numberListPluginStyle.copyWith(
  67. icon: (_, textNode) {
  68. const iconPadding = EdgeInsets.only(left: 5.0, right: 5.0);
  69. return Container(
  70. padding: iconPadding,
  71. child: Text(
  72. '${textNode.attributes.number.toString()}.',
  73. style: customEditorTheme(context).textStyle,
  74. ),
  75. );
  76. },
  77. );
  78. final pluginTheme = Theme.of(context).brightness == Brightness.dark
  79. ? darkPlguinStyleExtension
  80. : lightPlguinStyleExtension;
  81. return pluginTheme.toList()
  82. ..removeWhere((element) =>
  83. element is HeadingPluginStyle || element is NumberListPluginStyle)
  84. ..add(headingPluginStyle)
  85. ..add(numberListPluginStyle);
  86. }