2023-10-03 13:00:59 -04:00
|
|
|
import 'package:recon/string_formatter.dart';
|
2023-05-12 12:31:05 -04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class FormattedText extends StatelessWidget {
|
|
|
|
const FormattedText(this.formatTree, {
|
|
|
|
this.style,
|
|
|
|
this.textAlign,
|
|
|
|
this.overflow,
|
|
|
|
this.softWrap,
|
|
|
|
this.maxLines,
|
|
|
|
super.key
|
|
|
|
});
|
|
|
|
|
|
|
|
final FormatNode formatTree;
|
|
|
|
final TextStyle? style;
|
|
|
|
final TextAlign? textAlign;
|
|
|
|
final TextOverflow? overflow;
|
|
|
|
final bool? softWrap;
|
|
|
|
final int? maxLines;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (formatTree.isUnformatted) {
|
|
|
|
return Text(
|
|
|
|
formatTree.text,
|
|
|
|
style: style,
|
|
|
|
textAlign: textAlign,
|
|
|
|
overflow: overflow,
|
|
|
|
softWrap: softWrap,
|
|
|
|
maxLines: maxLines,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return RichText(
|
|
|
|
text: formatTree.toTextSpan(
|
|
|
|
baseStyle: style ?? Theme
|
|
|
|
.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyMedium!
|
|
|
|
),
|
|
|
|
textAlign: textAlign ?? TextAlign.start,
|
|
|
|
overflow: overflow ?? TextOverflow.clip,
|
|
|
|
softWrap: softWrap ?? true,
|
|
|
|
maxLines: maxLines,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|