editor_styles.dart 3.1 KB

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