editor_styles.dart 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.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<DocumentAppearanceCubit>().state;
  7. var editorStyle = Theme.of(context).brightness == Brightness.dark
  8. ? EditorStyle.dark
  9. : EditorStyle.light;
  10. editorStyle = editorStyle.copyWith(
  11. padding: const EdgeInsets.symmetric(horizontal: 100, vertical: 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.w600,
  22. fontFamily: 'poppins-Bold',
  23. ),
  24. backgroundColor: Theme.of(context).colorScheme.surface,
  25. selectionMenuBackgroundColor: Theme.of(context).cardColor,
  26. selectionMenuItemSelectedIconColor: Theme.of(context).colorScheme.onSurface,
  27. selectionMenuItemSelectedTextColor: Theme.of(context).colorScheme.onSurface,
  28. );
  29. return editorStyle;
  30. }
  31. Iterable<ThemeExtension<dynamic>> customPluginTheme(BuildContext context) {
  32. final documentStyle = context.watch<DocumentAppearanceCubit>().state;
  33. final baseFontSize = documentStyle.fontSize;
  34. const basePadding = 12.0;
  35. var headingPluginStyle = Theme.of(context).brightness == Brightness.dark
  36. ? HeadingPluginStyle.dark
  37. : HeadingPluginStyle.light;
  38. headingPluginStyle = headingPluginStyle.copyWith(
  39. textStyle: (EditorState editorState, Node node) {
  40. final headingToFontSize = {
  41. 'h1': baseFontSize + 12,
  42. 'h2': baseFontSize + 8,
  43. 'h3': baseFontSize + 4,
  44. 'h4': baseFontSize,
  45. 'h5': baseFontSize,
  46. 'h6': baseFontSize,
  47. };
  48. final fontSize =
  49. headingToFontSize[node.attributes.heading] ?? baseFontSize;
  50. return TextStyle(fontSize: fontSize, fontWeight: FontWeight.w600);
  51. },
  52. padding: (EditorState editorState, Node node) {
  53. final headingToPadding = {
  54. 'h1': basePadding + 6,
  55. 'h2': basePadding + 4,
  56. 'h3': basePadding + 2,
  57. 'h4': basePadding,
  58. 'h5': basePadding,
  59. 'h6': basePadding,
  60. };
  61. final padding = headingToPadding[node.attributes.heading] ?? basePadding;
  62. return EdgeInsets.only(bottom: padding);
  63. },
  64. );
  65. var numberListPluginStyle = Theme.of(context).brightness == Brightness.dark
  66. ? NumberListPluginStyle.dark
  67. : NumberListPluginStyle.light;
  68. numberListPluginStyle = numberListPluginStyle.copyWith(
  69. icon: (_, textNode) {
  70. const iconPadding = EdgeInsets.only(left: 5.0, right: 5.0);
  71. return Container(
  72. padding: iconPadding,
  73. child: Text(
  74. '${textNode.attributes.number.toString()}.',
  75. style: customEditorTheme(context).textStyle,
  76. ),
  77. );
  78. },
  79. );
  80. final pluginTheme = Theme.of(context).brightness == Brightness.dark
  81. ? darkPluginStyleExtension
  82. : lightPluginStyleExtension;
  83. return pluginTheme.toList()
  84. ..removeWhere(
  85. (element) =>
  86. element is HeadingPluginStyle || element is NumberListPluginStyle,
  87. )
  88. ..add(headingPluginStyle)
  89. ..add(numberListPluginStyle);
  90. }