-
Notifications
You must be signed in to change notification settings - Fork 399
Expand file tree
/
Copy pathstatus_line.dart
More file actions
342 lines (310 loc) · 11.1 KB
/
Copy pathstatus_line.dart
File metadata and controls
342 lines (310 loc) · 11.1 KB
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
// Copyright 2020 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
import 'package:devtools_app_shared/service.dart';
import 'package:devtools_app_shared/ui.dart';
import 'package:flutter/material.dart';
import 'package:vm_service/vm_service.dart';
import '../../shared/analytics/constants.dart' as gac;
import '../../shared/framework/screen.dart';
import '../../shared/globals.dart';
import '../../shared/primitives/utils.dart';
import '../../shared/ui/common_widgets.dart';
import '../../shared/ui/utils.dart';
import '../../shared/utils/utils.dart';
import 'scaffold.dart';
/// The status line widget displayed at the bottom of DevTools.
///
/// This displays information global to the application, as well as gives pages
/// a mechanism to display page-specific information.
class StatusLine extends StatelessWidget {
const StatusLine({
super.key,
required this.currentScreen,
required this.isEmbedded,
required this.isConnected,
}) : highlightForConnection = isConnected && !isEmbedded;
final Screen currentScreen;
final bool isEmbedded;
final bool isConnected;
/// Whether to highlight the footer when DevTools is connected to an app.
final bool highlightForConnection;
/// The padding around the footer in the DevTools UI.
EdgeInsets get padding => const EdgeInsets.symmetric(
horizontal: defaultSpacing,
vertical: densePadding,
);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final backgroundColor = highlightForConnection
? theme.colorScheme.primary
: null;
final foregroundColor = highlightForConnection
? theme.colorScheme.onPrimary
: null;
final height = statusLineHeight + padding.top + padding.bottom;
return ValueListenableBuilder<bool>(
valueListenable: currentScreen.showIsolateSelector,
builder: (context, showIsolateSelector, _) {
showIsolateSelector = showIsolateSelector && isConnected;
return DefaultTextStyle.merge(
style: TextStyle(color: foregroundColor),
child: Container(
decoration: BoxDecoration(
color: backgroundColor,
border: Border(
top: Divider.createBorderSide(context, width: 1.0),
),
),
padding: EdgeInsets.only(left: padding.left, right: padding.right),
height: height,
alignment: Alignment.centerLeft,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: _getStatusItems(context, showIsolateSelector),
),
),
);
},
);
}
List<Widget> _getStatusItems(BuildContext context, bool showIsolateSelector) {
final theme = Theme.of(context);
final foregroundColor = highlightForConnection
? theme.colorScheme.onPrimary
: null;
final screenWidth = ScreenSize(context).width;
// TODO(https://github.com/flutter/devtools/issues/8913): this builds the
// wrong status items for offline mode.
final pageStatus = currentScreen.buildStatus(context);
final widerThanXxs = screenWidth > MediaSize.xxs;
final screenMetaData = ScreenMetaData.lookup(currentScreen.screenId);
final showVideoTutorial = screenMetaData?.tutorialVideoTimestamp != null;
return [
Row(
mainAxisSize: MainAxisSize.min,
children: [
DocumentationLink(
screen: currentScreen,
screenWidth: screenWidth,
highlightForConnection: highlightForConnection,
),
if (showVideoTutorial) ...[
BulletSpacer(color: foregroundColor),
VideoTutorialLink(
screenMetaData: screenMetaData!,
screenWidth: screenWidth,
highlightForConnection: highlightForConnection,
),
],
],
),
BulletSpacer(color: foregroundColor),
if (widerThanXxs && showIsolateSelector) ...[
IsolateSelector(foregroundColor: foregroundColor),
BulletSpacer(color: foregroundColor),
],
if (screenWidth > MediaSize.xs && pageStatus != null) ...[
pageStatus,
BulletSpacer(color: foregroundColor),
],
buildConnectionStatus(context, screenWidth),
if (widerThanXxs && isEmbedded) ...[
BulletSpacer(color: foregroundColor),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: DevToolsScaffold.defaultActions(color: foregroundColor),
),
],
];
}
Widget buildConnectionStatus(BuildContext context, MediaSize screenWidth) {
final theme = Theme.of(context);
const noConnectionMsg = 'No client connection';
return ValueListenableBuilder<ConnectedState>(
valueListenable: serviceConnection.serviceManager.connectedState,
builder: (context, connectedState, child) {
if (connectedState.connected) {
final app = serviceConnection.serviceManager.connectedApp!;
String description;
if (!app.isRunningOnDartVM!) {
description = 'web app';
} else {
final vm = serviceConnection.serviceManager.vm!;
description = vm.deviceDisplay;
}
final color = highlightForConnection
? theme.colorScheme.onPrimary
: theme.regularTextStyle.color;
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ValueListenableBuilder(
valueListenable: serviceConnection.serviceManager.deviceBusy,
builder: (context, bool isBusy, _) {
return SizedBox(
width: smallProgressSize,
height: smallProgressSize,
child: isBusy
? SmallCircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color?>(color),
)
: const SizedBox(),
);
},
),
const SizedBox(width: denseSpacing),
DevToolsTooltip(
message: 'Connected device',
child: Text(
description,
style: highlightForConnection
? theme.regularTextStyle.copyWith(
color: theme.colorScheme.onPrimary,
)
: theme.regularTextStyle,
overflow: TextOverflow.clip,
),
),
],
);
} else {
return child!;
}
},
child: screenWidth <= MediaSize.xxs
? const DevToolsTooltip(
message: noConnectionMsg,
child: Icon(Icons.warning_amber_rounded, size: actionsIconSize),
)
: Text(noConnectionMsg, style: theme.regularTextStyle),
);
}
}
/// A widget that links to DevTools documentation on docs.flutter.dev for the
/// given [screen].
class DocumentationLink extends StatelessWidget {
const DocumentationLink({
super.key,
required this.screen,
required this.screenWidth,
required this.highlightForConnection,
});
final Screen screen;
final MediaSize screenWidth;
final bool highlightForConnection;
@override
Widget build(BuildContext context) {
final color = highlightForConnection
? Theme.of(context).colorScheme.onPrimary
: null;
final docPageId = screen.docPageId ?? '';
return LinkIconLabel(
icon: Icons.library_books_outlined,
link: GaLink(
display: screenWidth <= MediaSize.xs ? 'Docs' : 'Read docs',
url:
screen.docsUrl ??
'https://docs.flutter.dev/tools/devtools/$docPageId',
gaScreenName: screen.screenId,
gaSelectedItemDescription: gac.documentationLink,
),
color: color,
);
}
}
/// A widget that links to the "Dive in to DevTools" YouTube video at the
/// chapter for the given [screenMetaData].
class VideoTutorialLink extends StatelessWidget {
const VideoTutorialLink({
super.key,
required this.screenMetaData,
required this.screenWidth,
required this.highlightForConnection,
});
final ScreenMetaData screenMetaData;
final MediaSize screenWidth;
final bool highlightForConnection;
static const _devToolsYouTubeVideoUrl = 'https://youtu.be/_EYk-E29edo';
@override
Widget build(BuildContext context) {
final color = highlightForConnection
? Theme.of(context).colorScheme.onPrimary
: null;
return LinkIconLabel(
icon: Icons.ondemand_video_rounded,
link: GaLink(
display: screenWidth <= MediaSize.xs ? 'Tutorial' : 'Watch tutorial',
url:
'$_devToolsYouTubeVideoUrl${screenMetaData.tutorialVideoTimestamp}',
gaScreenName: screenMetaData.id,
gaSelectedItemDescription:
'${gac.videoTutorialLink}-${screenMetaData.id}',
),
color: color,
);
}
}
class IsolateSelector extends StatelessWidget {
const IsolateSelector({super.key, required this.foregroundColor});
final Color? foregroundColor;
@override
Widget build(BuildContext context) {
final isolateManager = serviceConnection.serviceManager.isolateManager;
return MultiValueListenableBuilder(
listenables: [isolateManager.isolates, isolateManager.selectedIsolate],
builder: (context, values, _) {
final isolates = values.first as List<IsolateRef>;
final selectedIsolateRef = values.second as IsolateRef?;
return PopupMenuButton<IsolateRef?>(
tooltip: 'Selected Isolate',
initialValue: selectedIsolateRef,
onSelected: isolateManager.selectIsolate,
itemBuilder: (BuildContext context) => isolates.map((ref) {
return PopupMenuItem<IsolateRef>(
value: ref,
child: _IsolateOption(
ref,
// This is always rendered against the background color
// for the pop up menu, which is the `surface` color.
color: Theme.of(context).colorScheme.onSurface,
),
);
}).toList(),
child: _IsolateOption(
isolateManager.selectedIsolate.value,
color: foregroundColor,
),
);
},
);
}
}
class _IsolateOption extends StatelessWidget {
const _IsolateOption(this.ref, {required this.color});
final IsolateRef? ref;
final Color? color;
@override
Widget build(BuildContext context) {
return Row(
children: [
Icon(
ref?.isSystemIsolate ?? false
? Icons.settings_applications
: Icons.call_split,
color: color,
),
const SizedBox(width: denseSpacing),
Text(
ref == null ? 'isolate' : _isolateName(ref!),
style: Theme.of(context).regularTextStyle.copyWith(color: color),
),
],
);
}
String _isolateName(IsolateRef ref) {
final name = ref.name;
return '$name #${serviceConnection.serviceManager.isolateManager.isolateIndex(ref)}';
}
}