editor_styles.dart 3.1 KB

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