forked from flutter/assets-for-api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heroes.dart
266 lines (246 loc) · 9.68 KB
/
heroes.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// Copyright 2014 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:flutter/material.dart';
import 'package:diagram_capture/diagram_capture.dart';
import 'diagram_step.dart';
import 'utils.dart';
class HeroesDiagram extends StatefulWidget implements DiagramMetadata {
const HeroesDiagram();
@override
String get name => 'heroes';
static const Color borderColor = Colors.black;
@override
_HeroesDiagramState createState() {
return _HeroesDiagramState();
}
}
class _HeroesDiagramState extends State<HeroesDiagram> {
final GlobalKey fromRoute = GlobalKey();
final GlobalKey toRoute = GlobalKey();
final GlobalKey fromHero = GlobalKey();
final GlobalKey fromPlaceholder = GlobalKey();
final GlobalKey toHero = GlobalKey();
final GlobalKey key = GlobalKey();
final GlobalKey heroKey = GlobalKey();
@override
Widget build(BuildContext context) {
return Directionality(
textDirection: TextDirection.ltr,
child: Container(
color: Colors.white,
height:480.0,
width: 900.0,
child: Stack(
children: <Widget>[
Center(
child: SizedBox(
width: 500.0,
child: Center(
child: Stack(
children: <Widget>[
Column(
key: heroKey,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
height: 400.0,
child: Stack(
children: <Widget>[
Positioned(
left: 0.0,
top: 0.0,
bottom: 0.0,
width: 300.0,
child: Material(
key: fromRoute,
color: Colors.grey[400],
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Align(
alignment: Alignment.centerLeft,
child: Container(
key: fromHero,
height: 100.0,
width: 100.0,
color: Colors.blue[300],
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
key: fromPlaceholder,
color: Colors.red[200],
),
),
),
),
),
),
),
Positioned(
right: 0.0,
top: 0.0,
bottom: 0.0,
width: 300.0,
child: Material(
key: toRoute,
color: Colors.grey[300],
elevation: 20.0,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Align(
alignment: const Alignment(1.0, -0.5),
child: Container(
key: toHero,
height: 180.0,
width: 180.0,
color: Colors.blue[300],
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
color: Colors.red[200],
child: const Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text('placeholderBuilder'),
),
),
),
),
),
),
),
),
),
],
),
),
const Padding(
padding: EdgeInsets.all(10.0),
child: CustomPaint(
painter: RightArrowPainter(fillColor: Colors.orange),
child: SizedBox(
height: 60.0,
width: 400.0,
child: Center(
child: Text(
'Push',
style: TextStyle(fontSize: 24.0),
),
),
),
),
),
],
),
Positioned(
left: 60.0,
top: 140.0,
child: Transform.rotate(
angle: -0.2,
child: CustomPaint(
size: const Size(320.0, 20.0),
painter: RightArrowPainter(fillColor: Colors.blue[600]!),
),
),
),
Positioned(
left: 140.0,
top: 100.0,
height: 140.0,
width: 140.0,
child: Container(
color: Colors.blue[400],
child: const Center(
child: Text('flightShuttleBuilder'),
),
),
)
],
),
),
),
),
Positioned.fill(
child: LabelPainterWidget(
key: key,
heroKey: heroKey,
labels: <Label>[
Label(
fromRoute,
'"bottom" route\nor\n"from" route (when pushing)',
const FractionalOffset(0.1, 0.95),
),
Label(
toRoute,
'"top" route\nor\n"to" route (when pushing)',
const FractionalOffset(0.9, 0.95),
),
Label(
fromHero,
'"from" hero (when pushing)',
const FractionalOffset(0.05, 0.95),
),
Label(
fromPlaceholder,
'placeholderBuilder',
const FractionalOffset(0.5, 0.6),
),
Label(
toHero,
'"to" hero (when pushing)',
const FractionalOffset(0.95, 0.95),
),
],
),
),
],
),
),
);
}
}
class RightArrowPainter extends CustomPainter {
const RightArrowPainter({ required this.fillColor });
final Color fillColor;
@override
void paint(Canvas canvas, Size size) {
final List<Offset> points = <Offset>[
const Offset(0.0, 0.0),
Offset(size.width - size.height / 2.0, 0.0),
Offset(size.width, size.height / 2.0),
Offset(size.width - size.height / 2.0, size.height),
Offset(0.0, size.height),
Offset(size.height / 2.0, size.height / 2.0),
];
final Path arrowPath = Path()..addPolygon(points, true);
canvas.drawPath(
arrowPath,
Paint()
..color = fillColor,
);
canvas.drawPath(
arrowPath,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 1.0
..color = HeroesDiagram.borderColor,
);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}
class HeroesDiagramStep extends DiagramStep<HeroesDiagram> {
HeroesDiagramStep(DiagramController controller) : super(controller);
@override
final String category = 'interaction';
@override
Future<List<HeroesDiagram>> get diagrams async => <HeroesDiagram>[const HeroesDiagram()];
@override
Future<File> generateDiagram(HeroesDiagram diagram) async {
controller.builder = (BuildContext context) => diagram;
return await controller.drawDiagramToFile(File('${diagram.name}.png'));
}
}