editor_styles.dart 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import 'package:appflowy_editor/appflowy_editor.dart';
  2. import 'package:flutter/material.dart';
  3. const _baseFontSize = 14.0;
  4. EditorStyle customEditorTheme(BuildContext context) {
  5. var editorStyle = Theme.of(context).brightness == Brightness.dark
  6. ? EditorStyle.dark
  7. : EditorStyle.light;
  8. editorStyle = editorStyle.copyWith(
  9. padding: const EdgeInsets.all(0),
  10. textStyle: editorStyle.textStyle?.copyWith(
  11. fontFamily: 'poppins',
  12. fontSize: _baseFontSize,
  13. ),
  14. placeholderTextStyle: editorStyle.placeholderTextStyle?.copyWith(
  15. fontFamily: 'poppins',
  16. fontSize: _baseFontSize,
  17. ),
  18. bold: editorStyle.bold?.copyWith(
  19. fontWeight: FontWeight.w500,
  20. ),
  21. backgroundColor: Theme.of(context).colorScheme.surface,
  22. );
  23. return editorStyle;
  24. }
  25. Iterable<ThemeExtension<dynamic>> customPluginTheme(BuildContext context) {
  26. const basePadding = 12.0;
  27. var headingPluginStyle = Theme.of(context).brightness == Brightness.dark
  28. ? HeadingPluginStyle.dark
  29. : HeadingPluginStyle.light;
  30. headingPluginStyle = headingPluginStyle.copyWith(
  31. textStyle: (EditorState editorState, Node node) {
  32. final headingToFontSize = {
  33. 'h1': _baseFontSize + 12,
  34. 'h2': _baseFontSize + 8,
  35. 'h3': _baseFontSize + 4,
  36. 'h4': _baseFontSize,
  37. 'h5': _baseFontSize,
  38. 'h6': _baseFontSize,
  39. };
  40. final fontSize =
  41. headingToFontSize[node.attributes.heading] ?? _baseFontSize;
  42. return TextStyle(fontSize: fontSize, fontWeight: FontWeight.w600);
  43. },
  44. padding: (EditorState editorState, Node node) {
  45. final headingToPadding = {
  46. 'h1': basePadding + 6,
  47. 'h2': basePadding + 4,
  48. 'h3': basePadding + 2,
  49. 'h4': basePadding,
  50. 'h5': basePadding,
  51. 'h6': basePadding,
  52. };
  53. final padding = headingToPadding[node.attributes.heading] ?? basePadding;
  54. return EdgeInsets.only(bottom: padding);
  55. },
  56. );
  57. final pluginTheme = Theme.of(context).brightness == Brightness.dark
  58. ? darkPlguinStyleExtension
  59. : lightPlguinStyleExtension;
  60. return pluginTheme.toList()
  61. ..removeWhere((element) => element is HeadingPluginStyle)
  62. ..add(headingPluginStyle);
  63. }