59 lines
1.4 KiB
Dart
59 lines
1.4 KiB
Dart
import 'dart:ui';
|
||
|
||
import 'package:flutter/cupertino.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:markdown_widget/widget/markdown_block.dart';
|
||
import 'package:markdown_widget/markdown_widget.dart';
|
||
|
||
|
||
class MarkdownSelectableText extends StatelessWidget {
|
||
final String data;
|
||
final TextStyle style;
|
||
|
||
const MarkdownSelectableText(
|
||
this.data, {
|
||
Key? key,
|
||
TextStyle? style,
|
||
}) : style = style ?? const TextStyle(),
|
||
super(key: key);
|
||
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return MarkdownBlock(
|
||
data: data,
|
||
selectable: true,
|
||
config: MarkdownConfig(configs:
|
||
[
|
||
// 段落
|
||
PConfig(textStyle:style),
|
||
|
||
// 标题 H1..H6(保留原始大小/粗细,但强制颜色)
|
||
H1Config(style: style),
|
||
H2Config(style: style),
|
||
H3Config(style: style),
|
||
H4Config(style: style),
|
||
H5Config(style: style),
|
||
H6Config(style: style),
|
||
|
||
// 链接(去掉下划线的话加 decoration: TextDecoration.none)
|
||
LinkConfig(style: style),
|
||
|
||
// 行内代码 / 代码块
|
||
CodeConfig(style: style),
|
||
PreConfig(
|
||
textStyle: style,
|
||
styleNotMatched:style,
|
||
|
||
),
|
||
|
||
// 引用块:它用单独的 textColor 字段
|
||
BlockquoteConfig(textColor: style.color??Colors.black),
|
||
|
||
// 表格头/体
|
||
TableConfig(headerStyle: style, bodyStyle: style),
|
||
]),
|
||
);
|
||
}
|
||
}
|