editor_styles.dart 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. placeholderTextStyle: editorStyle.placeholderTextStyle?.copyWith(
  15. fontFamily: 'poppins',
  16. fontSize: _baseFontSize,
  17. ),
  18. bold: editorStyle.bold?.copyWith(
  19. fontWeight: FontWeight.w500,
  20. ),
  21. );
  22. return editorStyle;
  23. }
  24. Iterable<ThemeExtension<dynamic>> customPluginTheme(BuildContext context) {
  25. final theme = context.watch<AppTheme>();
  26. const basePadding = 12.0;
  27. var headingPluginStyle =
  28. theme.isDark ? HeadingPluginStyle.dark : 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 =
  57. theme.isDark ? darkPlguinStyleExtension : lightPlguinStyleExtension;
  58. return pluginTheme.toList()
  59. ..removeWhere((element) => element is HeadingPluginStyle)
  60. ..add(headingPluginStyle);
  61. }