editor_styles.dart 2.1 KB

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