BetterText constructor
BetterText(
- String text, {
- Key? key,
- TextStyle? defaultStyle,
- Map<
String, TextStyle> styles = const {}, - Map<
String, VoidCallback> actions = const {}, - Map<
String, Color> colors = const {}, - Locale? locale,
- int? maxLines,
- TextOverflow overflow = TextOverflow.ellipsis,
- Color? selectionColor,
- SelectionRegistrar? selectionRegistrar,
- bool softWrap = true,
- StrutStyle? strutStyle,
- TextAlign textAlign = TextAlign.start,
- TextDirection? textDirection,
- TextHeightBehavior? textHeightBehavior,
- TextScaler textScaler = TextScaler.noScaling,
- TextWidthBasis textWidthBasis = TextWidthBasis.parent,
A widget that displays styled and interactive text.
BetterText allows you to easily create rich text with custom styles, colors, and interactive elements. It supports markdown-like syntax for applying styles and actions to specific parts of the text.
Example usage:
BetterText(
'Hello, {bold world}! {red Click me}',
styles: {'custom': TextStyle(fontStyle: FontStyle.italic)},
actions: {'tap': () => print('Tapped!')},
colors: {'primary': Colors.blue},
)
text is the string to be displayed, which can include style tokens in curly braces.
defaultStyle is the base style for the text.
styles is a map of custom style tokens to TextStyle objects.
actions is a map of action tokens to callback functions.
colors is a map of color tokens to Color objects.
The widget also supports standard text properties like textAlign, maxLines, etc.
Default tokens available:
- Font weights: 'thin', 'extraLight', 'light', 'regular', 'medium', 'semibold', 'bold', 'extraBold', 'heavy'
- Decorations: 'italic', 'underline', 'strike'
- Weight shorthands: '*' (bold), '/' (italic)
- Decoration shorthands: '_' (underline), '~' (strikethrough)
- Colors: 'red', 'blue', 'green', 'yellow', 'orange', 'purple', 'pink', 'brown', 'grey', 'black', 'white'
Implementation
BetterText(
this.text, {
super.key,
this.defaultStyle,
this.styles = const {},
this.actions = const {},
this.colors = const {},
// -- Standard rich text properties
this.locale,
this.maxLines,
this.overflow = TextOverflow.ellipsis,
this.selectionColor,
this.selectionRegistrar,
this.softWrap = true,
this.strutStyle,
this.textAlign = TextAlign.start,
this.textDirection,
this.textHeightBehavior,
this.textScaler = TextScaler.noScaling,
this.textWidthBasis = TextWidthBasis.parent,
});