forked from akvelon/flutter-code-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.dart
141 lines (130 loc) · 3.95 KB
/
error.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
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher_string.dart';
import '../analyzer/models/issue.dart';
import 'clickable.dart';
const errorIcon = Icon(
Icons.cancel,
color: Colors.red,
size: 16,
);
class GutterErrorWidget extends StatefulWidget {
final Issue issue;
final TextStyle popupTextStyle;
const GutterErrorWidget(
this.issue,
this.popupTextStyle,
);
@override
State<GutterErrorWidget> createState() => _GutterErrorWidgetState();
}
class _GutterErrorWidgetState extends State<GutterErrorWidget> {
OverlayEntry? _entry;
bool _mouseEnteredPopup = false;
@override
Widget build(BuildContext context) {
return MouseRegion(
onEnter: (event) {
setState(() {
_mouseEnteredPopup = false;
if (_entry != null) {
return;
}
_entry = _getErrorPopup();
final overlay = Overlay.of(context);
overlay.insert(_entry!);
});
},
onExit: (event) {
// Delay event here to keep overlay
// if mouse has exited the icon and entered popup.
Future.delayed(
const Duration(milliseconds: 50),
() {
setState(() {
if (!_mouseEnteredPopup) {
_entry?.remove();
_entry = null;
}
});
},
);
},
child: errorIcon,
);
}
OverlayEntry _getErrorPopup() {
final style = widget.popupTextStyle;
final issue = widget.issue;
final renderBox = context.findRenderObject() as RenderBox?;
if (renderBox == null) {
return OverlayEntry(builder: (context) => Container());
}
final width = renderBox.size.width;
final offset = renderBox.localToGlobal(Offset.zero);
return OverlayEntry(
builder: (context) {
return Positioned(
left: offset.dx + width,
top: offset.dy,
child: MouseRegion(
onEnter: (event) => setState(() {
_mouseEnteredPopup = true;
}),
onExit: (event) => setState(() {
_mouseEnteredPopup = false;
_entry?.remove();
_entry = null;
}),
child: DefaultTextStyle(
style: style,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.all(12),
constraints: const BoxConstraints(
minWidth: 100,
maxWidth: 500,
),
decoration: BoxDecoration(
color: style.backgroundColor,
border: style.color != null
? Border.all(
color: style.color!,
)
: null,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
issue.message,
),
if (issue.url != null) ...[
ClickableWidget(
child: Text(issue.url!),
onTap: () {
unawaited(launchUrlString(issue.url!));
},
),
],
if (issue.suggestion != null) ...[
Divider(
color: style.color,
),
Text(issue.suggestion!),
],
],
),
),
],
),
),
),
);
},
);
}
}