Skip to content

Commit

Permalink
Add DevTools section to Flutter sidebar (#7598)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll committed Apr 16, 2024
1 parent 1f15e20 commit 8f98a4b
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ class EmbeddedExtensionHeader extends StatelessWidget {
final extensionName = extension.displayName;
return Row(
children: [
RichText(
text: TextSpan(
text: 'package:$extensionName extension',
style: theme.regularTextStyle.copyWith(fontWeight: FontWeight.bold),
children: [
TextSpan(
text: ' (v${extension.version})',
style: theme.subtleTextStyle,
),
],
Padding(
padding: const EdgeInsets.only(left: borderPadding),
child: RichText(
text: TextSpan(
text: 'package:$extensionName extension',
style:
theme.regularTextStyle.copyWith(fontWeight: FontWeight.bold),
children: [
TextSpan(
text: ' (v${extension.version})',
style: theme.subtleTextStyle,
),
],
),
),
),
const Spacer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ final class VsCodeApiImpl extends ToolApiImpl implements VsCodeApi {

@override
Future<void> openDevToolsPage(
String debugSessionId, {
String? debugSessionId, {
String? page,
bool? forceExternal,
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract interface class VsCodeApi {
/// Depending on user settings, this may open embedded (the default) or in an
/// external browser window.
Future<void> openDevToolsPage(
String debugSessionId, {
String? debugSessionId, {
String? page,
bool? forceExternal,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class DebugSessions extends StatelessWidget {
style: Theme.of(context).textTheme.titleMedium,
),
if (sessions.isEmpty)
const Text('Begin a debug session to use DevTools.')
const Padding(
padding: EdgeInsets.only(left: borderPadding),
child: Text('No debug sessions'),
)
else
Table(
columnWidths: const {
Expand Down
131 changes: 131 additions & 0 deletions packages/devtools_app/lib/src/standalone_ui/vs_code/devtools.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright 2024 The Chromium 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 'dart:async';

import 'package:devtools_app_shared/ui.dart';
import 'package:flutter/material.dart';

import '../../shared/analytics/analytics.dart' as ga;
import '../../shared/analytics/constants.dart' as gac;
import '../../shared/screen.dart';
import '../api/vs_code_api.dart';

class DevToolsSidebarOptions extends StatelessWidget {
const DevToolsSidebarOptions({
required this.api,
super.key,
});

final VsCodeApi api;

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'DevTools',
style: theme.textTheme.titleMedium,
),
Table(
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
children: [
for (final screen
in ScreenMetaData.values.where(_shouldIncludeScreen))
_createDevToolsScreenRow(
label: screen.title ?? screen.id,
icon: screen.icon!,
screenId: screen.id,
api: api,
theme: theme,
),
if (api.capabilities.openDevToolsExternally)
_createDevToolsScreenRow(
label: 'Open in Browser',
icon: Icons.open_in_browser,
api: api,
theme: theme,
onPressed: () {
ga.select(
gac.VsCodeFlutterSidebar.id,
gac.VsCodeFlutterSidebar.openDevToolsExternally.name,
);
unawaited(api.openDevToolsPage(null, forceExternal: true));
},
),
],
),
const PaddedDivider.thin(),
const Padding(
padding: EdgeInsets.only(left: borderPadding),
child: Text(
'Begin a debug session to use tools that require a running '
'application.',
),
),
],
);
}

bool _shouldIncludeScreen(ScreenMetaData screen) {
return switch (screen) {
ScreenMetaData.home => false,
ScreenMetaData.vmTools => false,
// The performance and cpu profiler pages just show an option to load
// offline data. Hide them as they aren't that useful without a running
// app.
ScreenMetaData.performance => false,
ScreenMetaData.cpuProfiler => false,
_ => !screen.requiresConnection,
};
}
}

TableRow _createDevToolsScreenRow({
required String label,
required IconData icon,
required VsCodeApi api,
required ThemeData theme,
String? screenId,
void Function()? onPressed,
}) {
assert(
screenId != null || onPressed != null,
'screenId and onPressed cannot both be null',
);
final color = theme.colorScheme.secondary;
return TableRow(
children: [
SizedBox(
width: double.infinity,
child: TextButton.icon(
style: TextButton.styleFrom(
alignment: Alignment.centerLeft,
shape: const ContinuousRectangleBorder(),
textStyle: theme.regularTextStyle,
),
icon: Icon(
icon,
size: actionsIconSize,
color: color,
),
label: Text(
label,
style: theme.regularTextStyle.copyWith(color: color),
),
onPressed: onPressed ??
() {
ga.select(
gac.VsCodeFlutterSidebar.id,
gac.VsCodeFlutterSidebar.openDevToolsScreen(screenId!),
);
unawaited(api.openDevToolsPage(null, page: screenId));
},
),
),
],
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import '../api/dart_tooling_api.dart';
import '../api/vs_code_api.dart';
import 'debug_sessions.dart';
import 'devices.dart';
import 'devtools.dart';

/// A general Flutter sidebar panel for embedding inside IDEs.
///
Expand Down Expand Up @@ -107,13 +108,16 @@ class _VsCodeConnectedPanelState extends State<_VsCodeConnectedPanel> {
},
),
const SizedBox(height: defaultSpacing),
if (widget.api.capabilities.selectDevice)
if (widget.api.capabilities.selectDevice) ...[
Devices(
widget.api,
devices: devices,
unsupportedDevices: unsupportedDevices,
selectedDeviceId: devicesSnapshot.data?.selectedDeviceId,
),
const SizedBox(height: denseSpacing),
],
DevToolsSidebarOptions(api: widget.api),
],
);
},
Expand Down
3 changes: 2 additions & 1 deletion packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ TODO: Remove this section if there are not any general updates.

## VS Code Sidebar updates

TODO: Remove this section if there are not any general updates.
* Added a DevTools section with a list of tools that are available without a debug
session. - [#7598](https://github.com/flutter/devtools/pull/7598)

## DevTools Extension updates

Expand Down

0 comments on commit 8f98a4b

Please sign in to comment.