OpenContacts/lib/widgets/formatted_text.dart
2024-07-15 00:23:04 -04:00

47 lines
No EOL
1.1 KiB
Dart

import 'package:OpenContacts/string_formatter.dart';
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,
);
}
}
}