-
-
Notifications
You must be signed in to change notification settings - Fork 951
/
Copy pathrich_text_example.dart
89 lines (83 loc) · 2.84 KB
/
rich_text_example.dart
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame/text.dart';
import 'package:flutter/painting.dart';
class RichTextExample extends FlameGame {
final TextAlign textAlign;
RichTextExample({this.textAlign = TextAlign.left});
static const String description =
'A non-interactive example of how to render rich text in Flame.';
@override
Color backgroundColor() => const Color(0xFF888888);
@override
Future<void> onLoad() async {
final style = DocumentStyle(
width: 400,
height: 200,
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 14),
background: BackgroundStyle(
color: const Color(0xFF4E322E),
borderColor: const Color(0xFF000000),
borderWidth: 2.0,
),
paragraph: BlockStyle(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
textAlign: textAlign,
background: BackgroundStyle(
color: const Color(0xFF004D40),
borderColor: const Color(0xFFAAAAAA),
),
),
header1: BlockStyle(
textAlign: textAlign,
),
);
final document = DocumentRoot([
HeaderNode.simple('1984', level: 1),
ParagraphNode.simple(
'Anything could be true. The so-called laws of nature were nonsense.',
),
ParagraphNode.simple(
'The law of gravity was nonsense. "If I wished," O\'Brien had said, '
'"I could float off this floor like a soap bubble." Winston worked it '
'out. "If he thinks he floats off the floor, and I simultaneously '
'think I can see him do it, then the thing happens."',
),
ParagraphNode.group([
PlainTextNode(
'Suddenly, like a lump of submerged wreckage breaking the surface '
'of water, the thought burst into his mind: '),
ItalicTextNode.group([
PlainTextNode('"It doesn\'t really happen. We imagine it. It is '),
BoldTextNode.simple('hallucination'),
PlainTextNode('."'),
]),
]),
ParagraphNode.group([
PlainTextNode(
'He pushed the thought under instantly. The fallacy was obvious. It '
'presupposed that somewhere or other, outside oneself, there was a '
'"',
),
CodeTextNode.simple('real'),
PlainTextNode(
'" world where "',
),
CodeTextNode.simple('real'),
PlainTextNode(
'" things happened. But how could there be '
'such a world? What knowledge have we of anything, save through our '
'own minds? All happenings are in the mind. Whatever happens in all '
'minds, truly happens.',
),
]),
]);
add(
TextElementComponent.fromDocument(
document: document,
style: style,
position: Vector2(100, 50),
),
);
}
}