styled_text 1.0.1+1 styled_text: ^1.0.1+1 copied to clipboard
Text widget with formatting via tags. Makes it easier to use formatted text in multilingual applications.
styled_text #
Text widget with formatting via tags. Makes it easier to use formatted text in multilingual applications.
Formatting is set in the text using xml tags, for which styles are defined separately. It is also possible to insert icons through tags for which icons are set in styles.
You can set the click handler for the tag, through a special style ActionTextStyle.
Getting Started #
In your flutter project add the dependency:
dependencies:
...
styled_text: ^1.0.0
Import package:
import 'package:styled_text/styled_text.dart';
Usage example #
An example of making parts of text bold:
StyledText(
text: 'Test: <bold>bold</bold> text.',
styles: {
'bold': TextStyle(fontWeight: FontWeight.bold),
},
)
Example of highlighting a part of the text by different styles:
StyledText(
text: 'Test: <bold>bold</bold> and <red>red color</red> text.',
styles: {
'bold': TextStyle(fontWeight: FontWeight.bold),
'red': TextStyle(fontWeight: FontWeight.bold, color: Colors.red),
},
)
Example of inserting icons into the text:
StyledText(
text: 'Text with alarm <alarm/> icon.',
styles: {
'alarm': IconStyle(Icons.alarm),
},
)
Example of using a tag handler:
StyledText(
text: 'Text with <link href="https://flutter.dev">link</link> inside.',
styles: {
'link': ActionTextStyle(
decoration: TextDecoration.underline,
onTap: (TextSpan text, Map<String, String> attrs) => {
final String link = attrs['href'];
print('The "$link" link is tapped.');
},
),
},
)