MartenM / flutter_bbcode

A simple widget that renders BBCode in Flutter.
BSD 3-Clause "New" or "Revised" License
8 stars 5 forks source link

PubDev Pub Popularity GitHub Workflow Status

A simple display for BBCode in Flutter. Supports custom tags and styles.

Features

Preview

Preview 1 Preview 2

Getting started

  1. Install the package using the instruction on the installation page.
  2. That's all! You are ready to start displaying BBCode in Flutter.

Usage

A fully working example can be found on Github.

After installing the package displaying BBCode is rather straighforward. When using this code note that you will be using the all default available BBCode parsers.

Widget parsedBBCode = BBCodeText(data: _yourString);

Custom Stylesheet

An additional BBStylesheet can be provided using the stylesheet to overwrite the default style and tags used. Simply create an instance of BBStylesheet and add the tags you desire. It's also possible to get the default style and add, replace or remove certain tags.

var changedStyle = BBStyleSheet(tags: [
    BoldTag(),
    HeaderTag(1, 64)
]);

var extenedStyle = defaultBBStylesheet()
    .addTag(YourNewTag())
    .replaceTag(HeaderTag(1, 16));

Widget parsedBBCode = BBCodeText(data: _yourString, stylesheet: extendedStyle);

Creating your own tags

You can create your own tags by extending the AbstractTag, StyleTag, WrappedStyleTag or AdvancedTag classes. The StyleTag should be sufficient for most style changes. The WrappedStyleTag can be used to wrap a style around the tag. An example of a tag that implements this is the [quote] tag.

Additional information

Currently support tags by default

Contribute to the project

Feel free to create issues and pull-requests on Github. I will take a look at them as soon as possible.

Leaving a star is also highly appreciated :)