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