Skip to content
/ fxf Public

A Flutter package that converts plain text (txt) into Rich Text using style commands.

License

Notifications You must be signed in to change notification settings

getrod/fxf

Repository files navigation

fxf

A Flutter package that converts plain text (txt) into Rich Text using style commands.

Features

Change a text's boldness in the text itself.

'''
Hello *(5)World!
'''

hello_world Change many styles at the same time.

'''
Hello *(5)~(0xffff0000)World!*(d)~(d)
Hello *(5)~(0xff00ff00)World!*(d)~(d)
Hello *(5)~(0xff0000ff)World!*(d)~(d)
'''

hello_world_color Create links (with the help of url_launcher).

'''
Search #(https://www.google.com/)google#(d) for more information.
'''

link

Usage

Minimal example for getting started.

import 'package:fxf/fxf.dart' as fxf;

class MyWidget extends StatelessWidget {
  ...
  Widget build(BuildContext context) {
    return Center(
      child: fxf.Text("Hello *(5)World!"),
    );
  }
}

Example for creating links using url_launcher.

import 'package:fxf/fxf.dart' as fxf;
import 'package:url_launcher/url_launcher.dart';

class MyWidget extends StatelessWidget {
  ...
  Widget build(BuildContext context) {
    return Center(
      child: fxf.Text(
        "Search #(https://www.google.com/)google#(d) for more information.",
        onLinkTap: (link) {
          launchUrl(Uri.parse(link));
        },
      ),
    );
  }
}

Style Commands

* - bold
! - underline
^ - size
~ - color
` - italics
@ - font
# - link

Bold - *

*(weight: int)

weight: an integer clipped between [-3 - 5] and corresponds to FontWeight. 0 means normal font weight. 5 means FontWeight.w900. -3 means FontWeight.w100.

Underline - !

!(lineType: int, lineStyle: int, color: int)

lineType: an integer clipped between [0 - 3] and corresponds to TextDecoration:

  1. TextDecoration.none
  2. TextDecoration.underline
  3. TextDecoration.overline
  4. TextDecoration.lineThrough

lineStyle: an integer clipped between [0 - 4] and corresponds to TextDecorationStyle.

color: an integer clipped between [0x00000000 - 0xffffffff] and corresponds to TextStyle.decorationColor.

Size - ^

^(size: double)

size: a double clipped between [0 - infinity] and corresponds to TextStyle.fontSize.

Color - ~

~(color: int)

color: an integer clipped between [0x00000000 - 0xffffffff] and corresponds to TextStyle.color.

Italics - `

`(isOn: int)

isOn: an integer clipped between [0 - 1] and corresponds to FontStyle.

Font - @

@(font: str)

font: a string that corresponds to TextStyle.fontFamily.

Link - #

#(link: str, styleChange: int, color: int, isUnderline: int)

link: a string that holds the link.

styleChange: an integer clipped between [0 - 1]. If 0, the link text will not change it's style when hovered over. Otherwise, change link text style.

color: an integer clipped between [0x00000000 - 0xffffffff] and corresponds to TextStyle.color. This color will only appear when hovered over or clicked.

isUnderline: an integer clipped between [0 - 1]. If 0, the link will not be underlined. Otherwise, underline.

Default values - "d"

When style commands have as input "d" as in *(d), it defers to the default TextStyle for the corresponding style command. For example, if the default font weight is normal, then *(d) is actually *(0). If the default font weight is bold, then *(d) is *(3).

The same can be said for style commands with more than one parameter like underline. Not every parameter for underline needs to be specified in the style command. Ex: !(1) underlines the text, but keeps the default lineStyle and color alone.

For link commands, when #(d) is used, it's to end a link area (see example above).

Installation

In your pubspec.yaml, add to your dependencies:

dependencies:
    ...
    fxf:
        git:
            url: https://github.com/getrod/fxf.git

About

A Flutter package that converts plain text (txt) into Rich Text using style commands.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages