editor_styles.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import 'package:app_flowy/plugins/document/document.dart';
  2. import 'package:appflowy_editor/appflowy_editor.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:provider/provider.dart';
  5. EditorStyle customEditorTheme(BuildContext context) {
  6. final documentStyle = context.watch<DocumentStyle>();
  7. var editorStyle = Theme.of(context).brightness == Brightness.dark
  8. ? EditorStyle.dark
  9. : EditorStyle.light;
  10. editorStyle = editorStyle.copyWith(
  11. padding: const EdgeInsets.all(0),
  12. textStyle: editorStyle.textStyle?.copyWith(
  13. fontFamily: 'poppins',
  14. fontSize: documentStyle.fontSize,
  15. ),
  16. placeholderTextStyle: editorStyle.placeholderTextStyle?.copyWith(
  17. fontFamily: 'poppins',
  18. fontSize: documentStyle.fontSize,
  19. ),
  20. bold: editorStyle.bold?.copyWith(
  21. fontWeight: FontWeight.w500,
  22. ),
  23. backgroundColor: Theme.of(context).colorScheme.surface,
  24. );
  25. return editorStyle;
  26. }
  27. Iterable<ThemeExtension<dynamic>> customPluginTheme(BuildContext context) {
  28. final documentStyle = context.watch<DocumentStyle>();
  29. const basePadding = 12.0;
  30. var headingPluginStyle = Theme.of(context).brightness == Brightness.dark
  31. ? HeadingPluginStyle.dark
  32. : HeadingPluginStyle.light;
  33. headingPluginStyle = headingPluginStyle.copyWith(
  34. textStyle: (EditorState editorState, Node node) {
  35. final baseFontSize = documentStyle.fontSize;
  36. final headingToFontSize = {
  37. 'h1': baseFontSize + 12,
  38. 'h2': baseFontSize + 8,
  39. 'h3': baseFontSize + 4,
  40. 'h4': baseFontSize,
  41. 'h5': baseFontSize,
  42. 'h6': baseFontSize,
  43. };
  44. final fontSize =
  45. headingToFontSize[node.attributes.heading] ?? baseFontSize;
  46. return TextStyle(fontSize: fontSize, fontWeight: FontWeight.w600);
  47. },
  48. padding: (EditorState editorState, Node node) {
  49. final headingToPadding = {
  50. 'h1': basePadding + 6,
  51. 'h2': basePadding + 4,
  52. 'h3': basePadding + 2,
  53. 'h4': basePadding,
  54. 'h5': basePadding,
  55. 'h6': basePadding,
  56. };
  57. final padding = headingToPadding[node.attributes.heading] ?? basePadding;
  58. return EdgeInsets.only(bottom: padding);
  59. },
  60. );
  61. final pluginTheme = Theme.of(context).brightness == Brightness.dark
  62. ? darkPlguinStyleExtension
  63. : lightPlguinStyleExtension;
  64. return pluginTheme.toList()
  65. ..removeWhere((element) => element is HeadingPluginStyle)
  66. ..add(headingPluginStyle);
  67. }