forked from flutter/assets-for-api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_style.dart
134 lines (121 loc) · 4.18 KB
/
text_style.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:diagram_capture/diagram_capture.dart';
import 'package:flutter/material.dart';
import 'diagram_step.dart';
const String _bold = 'text_style_bold';
const String _italics = 'text_style_italics';
const String _opacityAndColor = 'text_style_opacity_and_color';
const String _size = 'text_style_size';
const String _wavyUnderline = 'text_style_wavy_red_underline';
const String _customFonts = 'text_style_custom_fonts';
class TextStyleDiagram extends StatelessWidget implements DiagramMetadata {
const TextStyleDiagram(this.name, {Key? key}) : super(key: key);
@override
final String name;
@override
Widget build(BuildContext context) {
late Widget returnWidget;
switch (name) {
case _bold:
returnWidget = const Text(
'No, we need bold strokes. We need this plan.',
style: TextStyle(fontWeight: FontWeight.bold),
);
break;
case _italics:
returnWidget = const Text(
"Welcome to the present, we're running a real nation.",
style: TextStyle(fontStyle: FontStyle.italic),
);
break;
case _opacityAndColor:
returnWidget = RichText(
text: TextSpan(
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
TextSpan(
text: "You don't have the votes.\n",
style: TextStyle(color: Colors.black.withOpacity(0.6)),
),
TextSpan(
text: "You don't have the votes!\n",
style: TextStyle(color: Colors.black.withOpacity(0.8)),
),
TextSpan(
text:
"You're gonna need congressional approval and you don't have the votes!\n",
style: TextStyle(color: Colors.black.withOpacity(1.0)),
),
],
),
);
break;
case _size:
returnWidget = Text(
"These are wise words, enterprising men quote 'em.",
style: DefaultTextStyle.of(context).style.apply(fontSizeFactor: 2.0),
);
break;
case _wavyUnderline:
returnWidget = RichText(
text: const TextSpan(
text: "Don't tax the South ",
style: TextStyle(color: Colors.black),
children: <TextSpan>[
TextSpan(
text: 'cuz',
style: TextStyle(
color: Colors.black,
decoration: TextDecoration.underline,
decorationColor: Colors.red,
decorationStyle: TextDecorationStyle.wavy,
),
),
TextSpan(
text: ' we got it made in the shade.',
),
],
),
);
break;
case _customFonts:
returnWidget = const Text(
'Look, when Britain taxed our tea, we got frisky.',
style: TextStyle(fontFamily: 'Raleway'),
);
break;
}
return ConstrainedBox(
key: UniqueKey(),
constraints: BoxConstraints.tight(const Size(300.0, 120.0)),
child: Container(
padding: const EdgeInsets.all(5.0),
color: Colors.white,
child: Center(child: returnWidget),
),
);
}
}
class TextStyleDiagramStep extends DiagramStep<TextStyleDiagram> {
TextStyleDiagramStep(DiagramController controller) : super(controller);
@override
final String category = 'painting';
@override
Future<List<TextStyleDiagram>> get diagrams async => <TextStyleDiagram>[
const TextStyleDiagram(_bold),
const TextStyleDiagram(_italics),
const TextStyleDiagram(_opacityAndColor),
const TextStyleDiagram(_size),
const TextStyleDiagram(_wavyUnderline),
const TextStyleDiagram(_customFonts),
];
@override
Future<File> generateDiagram(TextStyleDiagram diagram) async {
controller.builder = (BuildContext context) => diagram;
return controller.drawDiagramToFile(File('${diagram.name}.png'));
}
}