editor_styles.dart 2.1 KB

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