|
| 1 | +--- |
| 2 | +title: "Apply Themes" |
| 3 | +description: " How to theme your editor" |
| 4 | +lead: "" |
| 5 | +date: 2024-04-09T11:53:37+02:00 |
| 6 | +lastmod: 2024-04-09T11:53:37+02:00 |
| 7 | +draft: false |
| 8 | +images: [] |
| 9 | +menu: |
| 10 | + docs: |
| 11 | + parent: "how-to" |
| 12 | +weight: 999 |
| 13 | +toc: true |
| 14 | +--- |
| 15 | + |
| 16 | +## Customizing Text Styles and Heading Presets |
| 17 | + |
| 18 | +### Using the FleatherTheme Widget |
| 19 | + |
| 20 | +The FleatherTheme widget is designed to customize the appearance of document elements within both the FleatherToolbar and FleatherEditor. It accepts a FleatherThemeData object, which allows you to define your desired styling. |
| 21 | + |
| 22 | +``` dart |
| 23 | +FleatherTheme fleatherTheme = FleatherTheme(data: FleatherThemeData()); |
| 24 | +``` |
| 25 | +### Customizing the FleatherThemeData Widget |
| 26 | + |
| 27 | +To customize the FleatherTheme widget, you must specify all style variations. Note that it's not possible to define only a few styles. Here's how some styles work: |
| 28 | + |
| 29 | +* Bold, Italic, Underline, Strikethrough: These styles overlay the original text styling with the specified changes. For example, they are applied using a basic TextStyle widget that only modifies the relevant property. |
| 30 | +* Paragraph Style: This style applies to normal text. It's defined using a TextBlockTheme object, which includes style, decoration, and spacing variables. |
| 31 | + |
| 32 | +``` dart |
| 33 | +TextBlockTheme defaultTheme = TextBlockTheme( |
| 34 | + style: Theme.of(context).textTheme.bodyMedium!, |
| 35 | + spacing: VerticalSpacing(top: 1, bottom: 1), |
| 36 | + lineSpacing: VerticalSpacing(top: 3, bottom: 0), |
| 37 | + decoration: BoxDecoration(), |
| 38 | +); |
| 39 | +
|
| 40 | +FleatherThemeData fleatherTheme = FleatherThemeData( |
| 41 | + bold: TextStyle(fontWeight: FontWeight.bold), |
| 42 | + italic: TextStyle(fontStyle: FontStyle.italic), |
| 43 | + underline: TextStyle(decoration: TextDecoration.underline), |
| 44 | + strikethrough: TextStyle(decoration: TextDecoration.lineThrough), |
| 45 | + link: TextStyle(color: Colors.blue.shade700), |
| 46 | + paragraph: defaultTheme, |
| 47 | + heading1: TextBlockTheme(), |
| 48 | + heading2: TextBlockTheme(), |
| 49 | + heading3: TextBlockTheme(), |
| 50 | + heading4: TextBlockTheme(), |
| 51 | + heading6: TextBlockTheme() |
| 52 | + |
| 53 | + heading5: TextBlockTheme(), |
| 54 | + lists: TextBlockTheme(), |
| 55 | + quote: TextBlockTheme(), |
| 56 | + code: TextBlockTheme(), |
| 57 | + inlineCode: InlineCodeThemeData( |
| 58 | + style: TextStyle(), |
| 59 | + backgroundColor: Colors.grey.shade200, |
| 60 | + ), |
| 61 | +); |
| 62 | +``` |
| 63 | + |
| 64 | +### Applying a theme. |
| 65 | + |
| 66 | +To apply your custom theme, wrap the FleatherToolbar or FleatherEditor with the FleatherTheme widget and pass in your FleatherThemeData object as shown above. |
| 67 | + |
| 68 | +``` dart |
| 69 | +FleatherThemeData customTheme = FleatherThemeData( |
| 70 | + // Define your custom styles here |
| 71 | +); |
| 72 | +
|
| 73 | +FleatherTheme( |
| 74 | + data: customTheme, |
| 75 | + child: FleatherToolbar( |
| 76 | + // Toolbar content |
| 77 | + ), |
| 78 | +); |
| 79 | +``` |
0 commit comments