一个简单的包,用于在您的 Flutter 应用中轻松显示美观且完全可自定义的富文本,并带有标签。
特点
- 使用 * * 加粗,_ _ 斜体,~ ~ 删除线轻松创建富文本
- 通过 TextStyle 完全可自定义
- 样式内样式功能,即您可以根据需要嵌套样式。
- 您可以定义自己的自定义符号标签并按需设置样式
用法
在 pubspec.yaml 中添加此行
dependencies:
fast_rich_text: version,
导入包
import 'package:fast_rich_text/fast_rich_text.dart';
只需将 FastRichText 小部件添加到您应用中的任何位置
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: FastRichText(
text: textForChangeStyle,
textStyle: const TextStyle(
color: Colors.black,
),
),
),
);
}
您可以按以下方式为粗体、斜体和删除线提供自定义样式
FastRichText(
text: textForChangeStyle,
textStyle: const TextStyle(
color: Colors.black,
),
boldSTextStyle: const TextStyle(
color: Colors.red,
fontSize: 17,
fontWeight: FontWeight.bold,
),
italicTextStyle: const TextStyle(
color: Colors.green,
fontSize: 13,
letterSpacing: 4,
fontStyle: FontStyle.italic,
),
strikethroughTextStyle: const TextStyle(
color: Colors.blue,
decoration: TextDecoration.lineThrough,
),
),
您可以通过将 SymbolParams 列表传递给 customSymbols 字段来定义自定义标签。如果您只想解析自定义符号,则需要将 useCustomParseSymbolsOnly 设置为 true。默认情况下,将同时解析默认符号和自定义符号。任何出现多次的符号都将选择自定义符号中的第一个,并忽略其余的。
FastRichText(
text: textForCustomTags,
useCustomParseSymbolsOnly: true,
customSymbols: const [
SymbolParams(
symbolCharacter: '-',
style: TextStyle(
color: Colors.green,
fontSize: 13,
),
),
SymbolParams(
symbolCharacter: '/',
style: TextStyle(
color: Colors.purple,
fontSize: 13,
),
),
SymbolParams(
symbolCharacter: '#',
style: TextStyle(
color: Colors.blue,
fontSize: 13,
),
),
SymbolParams(
symbolCharacter: '&',
style: TextStyle(
color: Colors.blueAccent,
fontWeight: FontWeight.bold,
fontSize: 13,
),
)
],
textStyle: const TextStyle(
color: Colors.black,
),
),
FastRichText 演示
许可
MIT License
Copyright (c) 2022 Abdul-Jemeel Odewole
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

