-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathgesture_detector.dart
98 lines (84 loc) · 2.84 KB
/
gesture_detector.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
// 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';
const String _gestureDetector = 'gesture_detector';
const Duration _pauseDuration = Duration(seconds: 1);
final Duration _totalDuration = _pauseDuration + _pauseDuration;
class GestureDetectorDiagram extends StatefulWidget with DiagramMetadata {
const GestureDetectorDiagram(this.name, {super.key});
@override
final String name;
@override
State<GestureDetectorDiagram> createState() => _GestureDetectorDiagramState();
@override
Duration? get duration => _totalDuration;
}
class _GestureDetectorDiagramState extends State<GestureDetectorDiagram>
with TickerProviderStateMixin, LockstepStateMixin {
final GlobalKey _gestureDetectorKey = GlobalKey();
bool _lights = false;
Future<void> startAnimation() async {
await waitLockstep(_pauseDuration);
final RenderBox target =
_gestureDetectorKey.currentContext!.findRenderObject()! as RenderBox;
final Offset targetOffset = target.localToGlobal(
target.size.center(Offset.zero),
);
final WidgetController controller = DiagramWidgetController.of(context);
await controller.tapAt(targetOffset);
}
@override
void initState() {
super.initState();
startAnimation();
}
@override
Widget build(BuildContext context) {
return ConstrainedBox(
key: UniqueKey(),
constraints: BoxConstraints.tight(const Size(200, 150)),
child: Container(
alignment: FractionalOffset.center,
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
Icons.lightbulb_outline,
color: _lights ? Colors.yellow.shade600 : Colors.black,
size: 60,
),
),
GestureDetector(
key: _gestureDetectorKey,
onTap: () {
setState(() {
_lights = true;
});
},
child: Container(
color: Colors.yellow.shade600,
padding: const EdgeInsets.all(8),
child: const Text('TURN LIGHTS ON'),
),
),
],
),
),
);
}
}
class GestureDetectorDiagramStep extends DiagramStep {
@override
final String category = 'widgets';
@override
Future<List<GestureDetectorDiagram>> get diagrams async =>
<GestureDetectorDiagram>[const GestureDetectorDiagram(_gestureDetector)];
}