Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/devtools_app/lib/devtools_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export 'src/framework/scaffold/app_bar.dart';
export 'src/framework/scaffold/status_line.dart';
export 'src/screens/accessibility/accessibility_controller.dart';
export 'src/screens/accessibility/accessibility_screen.dart';
export 'src/screens/accessibility/semantics_node_details_pane.dart';
export 'src/screens/accessibility/semantics_node_model.dart';
export 'src/screens/app_size/app_size_controller.dart';
export 'src/screens/app_size/app_size_screen.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class AccessibilityController extends DevToolsScreenController
addAutoDisposeListener(boldText, _onBoldTextChanged);
addAutoDisposeListener(screenReader, _onScreenReaderChanged);
addAutoDisposeListener(highContrast, _onHighContrastChanged);
addAutoDisposeListener(semanticsRoots, _onSemanticsRootsChanged);
}

void _onSemanticsRootsChanged() {
selectSemanticsNode(semanticsRoots.value.firstOrNull);
}

void _initSemanticsTree() {
Expand Down Expand Up @@ -148,10 +153,19 @@ class AccessibilityController extends DevToolsScreenController
final highContrast = ValueNotifier<bool>(false);

final semanticsRoots = ValueNotifier<List<SemanticsNodeModel>>([]);
final selectedSemanticsNode = ValueNotifier<SemanticsNodeModel?>(null);
final semanticsTreeLoading = ValueNotifier<bool>(false);
final semanticsTreeError = ValueNotifier<String?>(null);
final treeScrollController = ScrollController();

/// Selects [node] in the semantics tree and unselects any previously selected node.
void selectSemanticsNode(SemanticsNodeModel? node) {
if (selectedSemanticsNode.value == node) return;
selectedSemanticsNode.value?.unselect();
node?.select();
selectedSemanticsNode.value = node;
}
Comment thread
hannah-hyj marked this conversation as resolved.

Future<void> loadSemanticsTree() async {
if (semanticsTreeLoading.value) return;

Expand All @@ -175,6 +189,8 @@ class AccessibilityController extends DevToolsScreenController
final response = await serviceConnection.serviceManager
.callServiceExtensionOnMainIsolate(registrations.getSemanticsTree);

if (disposed) return;

final json = response.json;
if (json != null && json.containsKey('error')) {
throw Exception(json['error']);
Expand Down Expand Up @@ -208,8 +224,10 @@ class AccessibilityController extends DevToolsScreenController
semanticsTreeError.value = null;
} catch (e, st) {
_log.warning('Error loading semantics tree: $e', e, st);
semanticsRoots.value = [];
semanticsTreeError.value = 'Failed to load semantics tree: $e';
if (!disposed) {
semanticsRoots.value = [];
semanticsTreeError.value = 'Failed to load semantics tree: $e';
}
} finally {
if (!disposed) {
semanticsTreeLoading.value = false;
Expand Down Expand Up @@ -253,10 +271,14 @@ class AccessibilityController extends DevToolsScreenController
SemanticsNodeModel _parseSemanticsNode(Map<String, dynamic> json) {
final rawFlags = json['flags'] as List<Object?>?;
final flags = SemanticsNodeModel.parseFlags(rawFlags);
final rect = SemanticsNodeModel.parseRect(json['rect']);

return SemanticsNodeModel(
id: json['id']?.toString() ?? '',
label: json['label']?.toString() ?? '',
value: json['value']?.toString() ?? '',
hint: json['hint']?.toString() ?? '',
rect: rect,
flags: flags,
widgetName: json['widgetName']?.toString() ?? '',
);
Expand All @@ -271,6 +293,7 @@ class AccessibilityController extends DevToolsScreenController
screenReader.dispose();
highContrast.dispose();
semanticsRoots.dispose();
selectedSemanticsNode.dispose();
semanticsTreeLoading.dispose();
semanticsTreeError.dispose();
treeScrollController.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import '../../shared/framework/screen.dart';
import '../../shared/globals.dart';
import 'accessibility_controller.dart';
import 'overrides_pane.dart';
import 'semantics_node_details_pane.dart';
import 'semantics_tree_pane.dart';

export 'overrides_pane.dart';
Expand Down Expand Up @@ -37,6 +38,12 @@ class _AccessibilityScreenBodyState extends State<AccessibilityScreenBody>
// ignore: unused-code, temporarily ignore since this screen is under active development.
late AccessibilityController controller;

/// The initial split fractions for the three screen panes:
/// - [AccessibilitySemanticsTreePane]: 35%
/// - [SemanticsNodeDetailsPane]: 35%
/// - [AccessibilityOverridesPane]: 30%
static const _initialFractions = [0.35, 0.35, 0.3];

@override
void initState() {
super.initState();
Expand All @@ -49,9 +56,10 @@ class _AccessibilityScreenBodyState extends State<AccessibilityScreenBody>
final splitAxis = _splitAxisFor(context);
return SplitPane(
axis: splitAxis,
initialFractions: const [0.6, 0.4],
initialFractions: _initialFractions,
children: const [
AccessibilitySemanticsTreePane(),
SemanticsNodeDetailsPane(),
AccessibilityOverridesPane(),
],
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
// Copyright 2026 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 'dart:ui' show SemanticsFlag;

import 'package:devtools_app_shared/ui.dart';
import 'package:material_ui/material_ui.dart';

import '../../shared/globals.dart';
import '../../shared/ui/common_widgets.dart';
import 'accessibility_controller.dart';
import 'semantics_node_model.dart';

/// A pane that displays the details of the currently selected semantics node.
class SemanticsNodeDetailsPane extends StatelessWidget {
const SemanticsNodeDetailsPane({super.key});

static const _paneTitle = 'Semantics Node Details';
static const _emptyMessage =
'Select a node in the semantics tree to view its details.';

@override
Widget build(BuildContext context) {
final controller = screenControllers.lookup<AccessibilityController>();
return DevToolsAreaPane(
header: const AreaPaneHeader(
title: Text(_paneTitle),
roundedTopBorder: false,
includeTopBorder: false,
),
child: ValueListenableBuilder<SemanticsNodeModel?>(
valueListenable: controller.selectedSemanticsNode,
builder: (context, selectedNode, _) {
if (selectedNode == null) {
return const CenteredMessage(message: _emptyMessage);
}
return _SemanticsNodeDetailsContent(node: selectedNode);
},
),
);
}
}

/// Displays the properties and flags of a selected [SemanticsNodeModel].
class _SemanticsNodeDetailsContent extends StatelessWidget {
const _SemanticsNodeDetailsContent({required this.node});

final SemanticsNodeModel node;

static const _labelTitle = 'label';
static const _labelDescription = 'The screen reader announcement text.';

static const _valueTitle = 'value';
static const _valueDescription =
'The current value of a progress indicator, slider, etc.';

static const _hintTitle = 'hint';
static const _hintDescription =
'A brief description of the action that will occur.';

static const _rectTitle = 'rect';
static const _rectDescription =
'The bounding box of the node in logical pixels.';

static const _flagsTitle = 'Flags';
static const _flagsDescription =
'Boolean flags that dictate the semantics behavior.';

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scrollbar(
child: SingleChildScrollView(
padding: const EdgeInsets.all(defaultSpacing),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('SemanticsNode #${node.id}', style: theme.boldTextStyle),
const SizedBox(height: denseSpacing),
const Divider(),
const SizedBox(height: denseSpacing),
_NodeDetailSection(
title: _labelTitle,
description: _labelDescription,
child: _NodeDetailValueBox(
text: node.label,
highlightText: true,
wrapInQuotes: true,
),
),
const SizedBox(height: defaultSpacing),
_NodeDetailSection(
title: _valueTitle,
description: _valueDescription,
child: _NodeDetailValueBox(text: node.value, wrapInQuotes: true),
),
const SizedBox(height: defaultSpacing),
_NodeDetailSection(
title: _hintTitle,
description: _hintDescription,
child: _NodeDetailValueBox(text: node.hint, wrapInQuotes: true),
),
const SizedBox(height: defaultSpacing),
_NodeDetailSection(
title: _rectTitle,
description: _rectDescription,
child: _NodeDetailValueBox(text: node.rectDisplay),
),
const SizedBox(height: defaultSpacing),
_NodeDetailSection(
title: _flagsTitle,
description: _flagsDescription,
child: node.flags.isEmpty
? const _NodeDetailValueBox(text: null)
: _SemanticsFlagsWrap(flags: node.flags),
),
],
),
),
);
}
}

/// A labeled section in the node details view with a title, description, and content.
class _NodeDetailSection extends StatelessWidget {
const _NodeDetailSection({
required this.title,
required this.description,
required this.child,
});

final String title;
final String description;
final Widget child;

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: theme.boldTextStyle),
const SizedBox(height: densePadding),
Text(description, style: theme.subtleTextStyle),
const SizedBox(height: denseSpacing),
child,
],
);
}
}

/// A bordered container that displays a property value or `(empty)` if none is present.
class _NodeDetailValueBox extends StatelessWidget {
const _NodeDetailValueBox({
required this.text,
this.highlightText = false,
this.wrapInQuotes = false,
});

final String? text;
final bool highlightText;
final bool wrapInQuotes;

static const _emptyPlaceholder = '(empty)';

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
final hasValue = text != null && text!.isNotEmpty;
final displayText = hasValue
? (wrapInQuotes ? '"$text"' : text!)
: _emptyPlaceholder;

return Container(
width: double.infinity,
padding: const EdgeInsets.all(defaultSpacing),
decoration: BoxDecoration(
color: colorScheme.onSurface.withValues(alpha: 0.05),
borderRadius: defaultBorderRadius,
border: Border.all(
color: highlightText && hasValue
? colorScheme.primary.withValues(alpha: 0.5)
: theme.focusColor,
),
),
child: SelectableText(
displayText,
style: _textStyle(theme, hasValue: hasValue),
),
);
}

TextStyle _textStyle(ThemeData theme, {required bool hasValue}) {
if (!hasValue) {
return theme.subtleFixedFontStyle;
}
if (highlightText) {
return theme.fixedFontStyle.copyWith(
color: theme.colorScheme.primary,
fontWeight: FontWeight.bold,
);
}
return theme.fixedFontStyle;
}
}

/// A wrapping layout of chips representing active [SemanticsFlag]s on a node.
class _SemanticsFlagsWrap extends StatelessWidget {
const _SemanticsFlagsWrap({required this.flags});

final Set<SemanticsFlag> flags;

@override
Widget build(BuildContext context) {
return Wrap(
spacing: denseSpacing,
runSpacing: denseSpacing,
children: [for (final flag in flags) _SemanticsFlagChip(flag: flag)],
);
}
}

/// A chip widget displaying the name of a single [SemanticsFlag].
class _SemanticsFlagChip extends StatelessWidget {
const _SemanticsFlagChip({required this.flag});

final SemanticsFlag flag;

static const _chipBorderRadius = 4.0;
static const _chipBackgroundAlpha = 0.12;

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
return Container(
padding: const EdgeInsets.symmetric(
horizontal: denseSpacing,
vertical: densePadding,
),
decoration: BoxDecoration(
color: colorScheme.onSurface.withValues(alpha: _chipBackgroundAlpha),
borderRadius: BorderRadius.circular(_chipBorderRadius),
),
child: Text(flag.name, style: theme.fixedFontStyle),
);
}
}
Loading
Loading