tex_text.dart
1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
library tex_text;
import 'package:flutter/material.dart';
import 'package:flutter_math_fork/flutter_math.dart';
export 'package:flutter_math_fork/flutter_math.dart';
/// A Calculator.
class TexText extends StatelessWidget {
const TexText(this.text,
{super.key,
this.style,
this.mathStyle = MathStyle.display,
this.alignment = WrapAlignment.start});
final String text;
final TextStyle? style;
final MathStyle mathStyle;
final WrapAlignment alignment;
@override
Widget build(BuildContext context) {
return Wrap(
alignment: alignment,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 4,
children: text
.split("<m>")
.asMap()
.map<int, List<Widget>>(
(index, e) {
if (index.isOdd) {
return MapEntry(
index,
[
Math.tex(
e,
textStyle: style,
mathStyle: mathStyle,
),
],
);
}
return MapEntry(
index,
e
.split(" ")
.map<Widget>((e) => Text(
e,
style: style,
))
.toList(),
);
},
)
.values
.toList()
.expand<Widget>((element) => element)
.toList(),
);
}
}