A Flutter package that converts plain text (txt) into Rich Text using style commands.
Change a text's boldness in the text itself.
'''
Hello *(5)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)
'''
Create links (with the help of url_launcher).
'''
Search #(https://www.google.com/)google#(d) for more information.
'''
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));
},
),
);
}
}
* - bold
! - underline
^ - size
~ - color
` - italics
@ - font
# - link
*(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.
!(lineType: int, lineStyle: int, color: int)
lineType: an integer clipped between [0 - 3] and corresponds to TextDecoration:
lineStyle: an integer clipped between [0 - 4] and corresponds to TextDecorationStyle.
color: an integer clipped between [0x00000000 - 0xffffffff] and corresponds to TextStyle.decorationColor.
^(size: double)
size: a double clipped between [0 - infinity] and corresponds to TextStyle.fontSize.
~(color: int)
color: an integer clipped between [0x00000000 - 0xffffffff] and corresponds to TextStyle.color.
`(isOn: int)
isOn: an integer clipped between [0 - 1] and corresponds to FontStyle.
@(font: str)
font: a string that corresponds to TextStyle.fontFamily.
#(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.
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).
In your pubspec.yaml
, add to your dependencies:
dependencies:
...
fxf:
git:
url: https://github.com/getrod/fxf.git