editor_styles.dart 3.1 KB

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