-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathon_gesture.dart
70 lines (61 loc) · 2.15 KB
/
on_gesture.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
import 'package:flutter/material.dart';
import 'package:custom_text/custom_text.dart';
import 'package:custom_text_example/common/popup.dart';
class OnGestureExample extends StatefulWidget {
const OnGestureExample(this.output);
final void Function(String) output;
@override
State<OnGestureExample> createState() => _OnGestureExampleState();
}
class _OnGestureExampleState extends State<OnGestureExample> {
late final _controller = PopupController();
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
const matchStyle = TextStyle(color: Color(0xFF3366CC));
return CustomText(
'Flutter is an [open-source]() [UI]() [software development kit]() '
'created by [Google](). It is used to develop [cross-platform '
'applications]() for [Android](), [iOS](), [Linux](), [macOS](), '
'[Windows](), [Google Fuchsia](), and the [web]() from a single '
'[codebase]().',
definitions: [
TextDefinition(
matcher: ExactMatcher(const ['Flutter']),
matchStyle: const TextStyle(fontWeight: FontWeight.bold),
),
SelectiveDefinition(
matcher: const LinkMatcher(),
shownText: (element) => element.groups.first!,
matchStyle: matchStyle,
hoverStyle: matchStyle.copyWith(
decoration: TextDecoration.underline,
),
onTap: (details) {
_output(details);
_controller.toggle(context, details);
},
onGesture: (details) {
_output(details);
if (details.gestureKind == GestureKind.enter) {
_controller.show(context, details);
} else if (details.gestureKind == GestureKind.exit) {
_controller.startCloseTimer(const Duration(milliseconds: 200));
}
},
),
],
);
}
void _output(GestureDetails details) {
final x = details.globalPosition.dx.roundToDouble();
final y = details.globalPosition.dy.roundToDouble();
widget.output(
'${details.shownText}\n ${details.gestureKind.name} ($x, $y)',
);
}
}