editor_styles.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import 'package:appflowy_editor/appflowy_editor.dart';
  2. import 'package:flowy_infra/theme.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:provider/provider.dart';
  5. EditorStyle customEditorStyle(BuildContext context) {
  6. final theme = context.watch<AppTheme>();
  7. const baseFontSize = 14.0;
  8. const basePadding = 12.0;
  9. var textStyle = theme.isDark
  10. ? BuiltInTextStyle.builtInDarkMode()
  11. : BuiltInTextStyle.builtIn();
  12. textStyle = textStyle.copyWith(
  13. defaultTextStyle: textStyle.defaultTextStyle.copyWith(
  14. fontFamily: 'poppins',
  15. fontSize: baseFontSize,
  16. ),
  17. bold: textStyle.bold.copyWith(
  18. fontWeight: FontWeight.w500,
  19. ),
  20. );
  21. return EditorStyle.defaultStyle().copyWith(
  22. padding: const EdgeInsets.symmetric(horizontal: 80),
  23. textStyle: textStyle,
  24. pluginStyles: {
  25. 'text/heading': builtInPluginStyle
  26. ..update(
  27. 'textStyle',
  28. (_) => (EditorState editorState, Node node) {
  29. final headingToFontSize = {
  30. 'h1': baseFontSize + 12,
  31. 'h2': baseFontSize + 8,
  32. 'h3': baseFontSize + 4,
  33. 'h4': baseFontSize,
  34. 'h5': baseFontSize,
  35. 'h6': baseFontSize,
  36. };
  37. final fontSize =
  38. headingToFontSize[node.attributes.heading] ?? baseFontSize;
  39. return TextStyle(fontSize: fontSize, fontWeight: FontWeight.w600);
  40. },
  41. )
  42. ..update(
  43. 'padding',
  44. (_) => (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 =
  54. headingToPadding[node.attributes.heading] ?? basePadding;
  55. return EdgeInsets.only(bottom: padding);
  56. },
  57. )
  58. },
  59. );
  60. }