-
Notifications
You must be signed in to change notification settings - Fork 106
/
ink_well.dart
123 lines (109 loc) · 3.53 KB
/
ink_well.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
// 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 'package:diagram_capture/diagram_capture.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'diagram_step.dart';
import 'utils.dart';
final GlobalKey _splashKey = GlobalKey();
class InkWellDiagram extends StatefulWidget with DiagramMetadata {
const InkWellDiagram({super.key});
@override
String get name => 'ink_well';
@override
Duration get startAt => const Duration(milliseconds: 550);
@override
State<InkWellDiagram> createState() => _InkWellDiagramState();
}
class _InkWellDiagramState extends State<InkWellDiagram>
with TickerProviderStateMixin, LockstepStateMixin {
final GlobalKey canvasKey = GlobalKey();
final GlobalKey childKey = GlobalKey();
final GlobalKey heroKey = GlobalKey();
Future<void> startAnimation() async {
// Wait for the tree to finish building before attempting to find our
// RenderObject.
await Future<void>.delayed(Duration.zero);
final WidgetController controller = DiagramWidgetController.of(context);
final RenderBox target =
_splashKey.currentContext!.findRenderObject()! as RenderBox;
final Offset targetOffset =
target.localToGlobal(target.size.bottomRight(Offset.zero));
final TestGesture gesture = await controller.startGesture(targetOffset);
await waitLockstep(const Duration(seconds: 1));
gesture.up();
}
@override
void initState() {
super.initState();
startAnimation();
}
@override
Widget build(BuildContext context) {
return ConstrainedBox(
key: UniqueKey(),
constraints: BoxConstraints.tight(const Size(280.0, 180.0)),
child: Theme(
data: ThemeData(
primarySwatch: Colors.blue,
),
child: Material(
color: const Color(0xFFFFFFFF),
child: Stack(
children: <Widget>[
Center(
child: SizedBox(
width: 150.0,
height: 100.0,
child: InkWell(
key: heroKey,
onTap: () {},
child: Hole(
color: Colors.blue,
key: childKey,
),
),
),
),
Center(
child: Container(
width: 120.0,
height: 80.0,
alignment: FractionalOffset.bottomRight,
child: SizedBox(
key: _splashKey,
width: 20.0,
height: 25.0,
),
),
),
Positioned.fill(
child: LabelPainterWidget(
key: canvasKey,
labels: <Label>[
Label(childKey, 'child', const FractionalOffset(0.2, 0.8)),
Label(_splashKey, 'splash', FractionalOffset.topLeft),
Label(
heroKey, 'highlight', const FractionalOffset(0.3, 0.2)),
],
heroKey: heroKey,
),
),
],
),
),
),
);
}
}
class InkWellDiagramStep extends DiagramStep {
@override
final String category = 'material';
@override
Future<List<DiagramMetadata>> get diagrams async {
return const <DiagramMetadata>[
InkWellDiagram(),
];
}
}