A customizable toolbar to enhance your experience of writing Markdown in Flutter apps.

This plugin uses the TextField widget from Flutter (read more below). In the future, it may become independent from it to change any text, no matter where it's coming from.

Table of Contents

Screenshots

Preview GIF

Responsive wrapping and collapsable

Horizontal toolbar Horizontal toolbar collapsed

Vertical responsive toolbar Vertical responsive toolbar collapsed

Features

Convert your text to these styles:

Convert toIn MarkdownSupported
Heading (1-6)# Heading
Bold**Bold**
Italic*Italic*
Strikethrough~~Strikethrough~~
Link[Link](https://pub.dev)
Image![Image](assets/image.png)
Code```Code```
Bulleted list- Bulleted list
Numbered list1. Numbered list
Checkbox- [ ] Checkbox and - [x] Checkbox
Quote> Quote
Horizontal rule---

About the toolbar:

  • Platform-independent
  • Responsive wrapping (+ optionally collapsable)
  • RTL support (by setting textDirection: TextDirection.rtl in your custom TextField)
  • Easy to implement
  • Uses its own parser that can be made more precise over time
  • No other dependencies apart from the Flutter widgets

Usage

First, import the package:

import 'package:markdown_toolbar/markdown_toolbar.dart';

You have 2 options:

1. Quick integration

For quick integration, simply add the MarkdownToolbar widget (which includes a TextField) and you're done:

const MarkdownToolbar(useIncludedTextField: true),

2. Custom TextField

However, if you want to use your own TextField, declare your TextEditingController and FocusNode and set them to the controller and focusNode fields respectively (for both the TextField and MarkdownToolbar widgets):

final TextEditingController _controller = TextEditingController(); // Declare the TextEditingController
late final FocusNode _focusNode; // Declare the FocusNode

@override
void initState() {
    _controller.addListener(() => setState(() {})); // Update the text when typing
    _focusNode = FocusNode(); // Assign a FocusNode
    super.initState();
}

@override
void dispose() {
    _controller.dispose(); // Dispose the TextEditingController
    _focusNode.dispose(); // Dispose the FocusNode
    super.dispose();
}

// Inside a Column for instance, place the widgets and assign the fields
Column(children: <Widget>[
    MarkdownToolbar(
        useIncludedTextField: false, // Because we want to use our own, set useIncludedTextField to false
        controller: _controller, // Add the _controller
        focusNode: _focusNode, // Add the _focusNode
    ),
    TextField(
        controller: _controller, // Add the _controller
        focusNode: _focusNode, // Add the _focusNode
    ),
])

For a complete example, check out example.dart.

Customization options:

PropertyTypeDefaultDescription
useIncludedTextFieldboolN/A, requiredUse the included TextField
controllerTextEditingController?N/ASet a custom TextEditingController if useIncludedTextField is set to false
focusNodeFocusNode?N/ASet a custom FocusNode if useIncludedTextField is set to false
collapsablebooltrueShow a button to collapse the toolbar
alignCollapseButtonEndboolfalseAlign the collapse button at the end, not at the start
flipCollapseButtonIconboolfalseFlip the collapse button icon
backgroundColorColorColor(0xFFEEEEEE)Background color of the buttons
dropdownTextColorColorColors.blueText color in the dropdown selections
iconColorColorColor(0xFF303030)Icon color of the buttons
iconSizedouble24.0Icon size of the buttons
widthdouble60.0Width of the buttons
heightdouble40.0Height of the buttons
spacingdouble4.0Spacing between the buttons
runSpacingdouble4.0Vertical spacing between the buttons
alignmentWrapAlignmentWrapAlignment.endWrapAlignment of the buttons
boldCharacterString'**'Markdown character for bold text
italicCharacterString'*'Markdown character for italic text
codeCharacterString'```'Markdown character for code
bulletedListCharacterString'-'Markdown character for bulleted lists
horizontalRuleCharacterString'---'Markdown character for horizontal rules
hideButton 1-9boolfalseHide certain buttons in the toolbar (replace Button with the available buttons)
showTooltipsbooltrueShow tooltips for the buttons
button 1-9TooltipString'Name of button'Custom tooltips when hovering over the buttons (replace button with the available buttons)

You can also hover over the MarkdownToolbar widget and its fields inside your IDE to receive more information regarding all the options.

Roadmap

  • Ability to rearrange the buttons through a List (and thus remove the need for hideButton booleans, as you can simply not include the unwanted buttons inside the list)
  • Custom character support for all buttons to change the added Markdown characters on click
  • Custom button support
  • Custom function support when clicking a button (Useful for integrating things like a File Picker when inserting an Image instead of having to manually type out the path)
  • Add Emoji button

Libraries

markdown_toolbar