editor_styles.dart 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import 'package:appflowy/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: 0),
  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:
  26. Theme.of(context).textTheme.bodyMedium?.color,
  27. selectionMenuItemSelectedTextColor:
  28. Theme.of(context).textTheme.bodyMedium?.color,
  29. );
  30. return editorStyle;
  31. }
  32. Iterable<ThemeExtension<dynamic>> customPluginTheme(BuildContext context) {
  33. final documentStyle = context.watch<DocumentAppearanceCubit>().state;
  34. final baseFontSize = documentStyle.fontSize;
  35. const basePadding = 12.0;
  36. var headingPluginStyle = Theme.of(context).brightness == Brightness.dark
  37. ? HeadingPluginStyle.dark
  38. : HeadingPluginStyle.light;
  39. headingPluginStyle = headingPluginStyle.copyWith(
  40. textStyle: (EditorState editorState, Node node) {
  41. final headingToFontSize = {
  42. 'h1': baseFontSize + 12,
  43. 'h2': baseFontSize + 8,
  44. 'h3': baseFontSize + 4,
  45. 'h4': baseFontSize,
  46. 'h5': baseFontSize,
  47. 'h6': baseFontSize,
  48. };
  49. final fontSize =
  50. headingToFontSize[node.attributes.heading] ?? baseFontSize;
  51. return TextStyle(fontSize: fontSize, fontWeight: FontWeight.w600);
  52. },
  53. padding: (EditorState editorState, Node node) {
  54. final headingToPadding = {
  55. 'h1': basePadding + 6,
  56. 'h2': basePadding + 4,
  57. 'h3': basePadding + 2,
  58. 'h4': basePadding,
  59. 'h5': basePadding,
  60. 'h6': basePadding,
  61. };
  62. final padding = headingToPadding[node.attributes.heading] ?? basePadding;
  63. return EdgeInsets.only(bottom: padding);
  64. },
  65. );
  66. var numberListPluginStyle = Theme.of(context).brightness == Brightness.dark
  67. ? NumberListPluginStyle.dark
  68. : NumberListPluginStyle.light;
  69. numberListPluginStyle = numberListPluginStyle.copyWith(
  70. icon: (_, textNode) {
  71. const iconPadding = EdgeInsets.only(left: 5.0, right: 5.0);
  72. return Container(
  73. padding: iconPadding,
  74. child: Text(
  75. '${textNode.attributes.number.toString()}.',
  76. style: customEditorTheme(context).textStyle,
  77. ),
  78. );
  79. },
  80. );
  81. final pluginTheme = Theme.of(context).brightness == Brightness.dark
  82. ? darkPlguinStyleExtension
  83. : lightPlguinStyleExtension;
  84. return pluginTheme.toList()
  85. ..removeWhere((element) =>
  86. element is HeadingPluginStyle || element is NumberListPluginStyle)
  87. ..add(headingPluginStyle)
  88. ..add(numberListPluginStyle);
  89. }