feat(semantics): add semantic labels for UI automation
- Created lib/core/semantics/ with semantic ID constants and helper widget
- Enabled SemanticsBinding on web builds for accessibility tree exposure
- Added semantic IDs to:
- ProfileDropdown (button, settings, theme options, logout)
- TopHeaderBar room tabs (frontHall, controlRoom, security, parlor)
- NavPanel items (nav_item_{id})
This enables browser automation tools like Puppeteer and WebDriver to
discover and interact with Flutter widgets via the accessibility tree.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
04032a6dbc
commit
a6c51f757a
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.2.0] - 2026-01-05
|
||||
|
||||
### Added
|
||||
- **Semantic labels for UI automation** (`lib/core/semantics/`)
|
||||
- `semantic_ids.dart` - Centralized semantic identifier constants
|
||||
- `semantic_widget.dart` - Helper widget and extension for adding semantics
|
||||
- Enables browser automation tools (Puppeteer, WebDriver) via accessibility tree
|
||||
- Semantic IDs added to:
|
||||
- Profile dropdown button and menu items (theme options, settings, logout)
|
||||
- Room navigation tabs (Front Hall, Control Room, Security, Parlor)
|
||||
- NavPanel items (sidebar navigation)
|
||||
- `SemanticsBinding.instance.ensureSemantics()` enabled on web builds
|
||||
|
||||
## [1.1.16] - 2026-01-05
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/// Semantic identifiers for UI automation and accessibility.
|
||||
///
|
||||
/// These IDs are exposed via Flutter's Semantics tree, making widgets
|
||||
/// discoverable by automation tools (Appium, WebDriver, Puppeteer with
|
||||
/// accessibility enabled).
|
||||
///
|
||||
/// Naming convention: `{area}_{component}_{identifier}`
|
||||
/// - area: room or feature area (e.g., profile, nav, dataGrid)
|
||||
/// - component: widget type (e.g., menu, button, row)
|
||||
/// - identifier: specific item (e.g., light, containers, selectAll)
|
||||
library;
|
||||
|
||||
/// Profile dropdown menu IDs.
|
||||
abstract class ProfileSemantics {
|
||||
static const button = 'profile_button';
|
||||
static const menu = 'profile_menu';
|
||||
static const settings = 'profile_menu_settings';
|
||||
static const themeSystem = 'profile_menu_theme_system';
|
||||
static const themeLight = 'profile_menu_theme_light';
|
||||
static const themeDark = 'profile_menu_theme_dark';
|
||||
static const logout = 'profile_menu_logout';
|
||||
}
|
||||
|
||||
/// Room tab navigation IDs.
|
||||
abstract class RoomTabSemantics {
|
||||
static const frontHall = 'roomTab_frontHall';
|
||||
static const controlRoom = 'roomTab_controlRoom';
|
||||
static const security = 'roomTab_security';
|
||||
static const parlor = 'roomTab_parlor';
|
||||
|
||||
/// Get semantic ID for room index.
|
||||
static String forIndex(int index) => switch (index) {
|
||||
0 => frontHall,
|
||||
1 => controlRoom,
|
||||
2 => security,
|
||||
3 => parlor,
|
||||
_ => 'roomTab_$index',
|
||||
};
|
||||
}
|
||||
|
||||
/// Navigation panel IDs.
|
||||
abstract class NavSemantics {
|
||||
static const panel = 'nav_panel';
|
||||
static const refresh = 'nav_refresh';
|
||||
|
||||
/// Generate ID for a nav item.
|
||||
static String item(String id) => 'nav_item_$id';
|
||||
|
||||
/// Generate ID for a nav section.
|
||||
static String section(String id) => 'nav_section_$id';
|
||||
}
|
||||
|
||||
/// DataGrid component IDs.
|
||||
abstract class DataGridSemantics {
|
||||
static const grid = 'dataGrid';
|
||||
static const search = 'dataGrid_search';
|
||||
static const searchClear = 'dataGrid_search_clear';
|
||||
static const selectAll = 'dataGrid_selectAll';
|
||||
static const loading = 'dataGrid_loading';
|
||||
static const empty = 'dataGrid_empty';
|
||||
static const error = 'dataGrid_error';
|
||||
static const refresh = 'dataGrid_refresh';
|
||||
|
||||
/// Generate ID for a column header.
|
||||
static String header(String columnId) => 'dataGrid_header_$columnId';
|
||||
|
||||
/// Generate ID for a row.
|
||||
static String row(String itemId) => 'dataGrid_row_$itemId';
|
||||
|
||||
/// Generate ID for a row checkbox.
|
||||
static String rowCheckbox(String itemId) => 'dataGrid_row_${itemId}_checkbox';
|
||||
|
||||
/// Generate ID for a row actions menu.
|
||||
static String rowActions(String itemId) => 'dataGrid_row_${itemId}_actions';
|
||||
|
||||
/// Generate ID for a row action.
|
||||
static String rowAction(String itemId, String actionId) =>
|
||||
'dataGrid_row_${itemId}_action_$actionId';
|
||||
|
||||
/// Generate ID for a bulk action button.
|
||||
static String bulkAction(String actionId) => 'dataGrid_bulk_$actionId';
|
||||
|
||||
static const bulkClear = 'dataGrid_bulk_clear';
|
||||
}
|
||||
|
||||
/// Dialog/modal IDs.
|
||||
abstract class DialogSemantics {
|
||||
static const confirm = 'dialog_confirm';
|
||||
static const cancel = 'dialog_cancel';
|
||||
static const close = 'dialog_close';
|
||||
|
||||
/// Generate ID for a named dialog.
|
||||
static String named(String name) => 'dialog_$name';
|
||||
|
||||
/// Generate ID for a dialog action button.
|
||||
static String action(String dialogName, String actionId) =>
|
||||
'dialog_${dialogName}_$actionId';
|
||||
}
|
||||
|
||||
/// Settings page IDs.
|
||||
abstract class SettingsSemantics {
|
||||
static const themeDropdown = 'settings_theme';
|
||||
static const defaultRoomDropdown = 'settings_defaultRoom';
|
||||
}
|
||||
|
||||
/// Loading/state indicator IDs.
|
||||
abstract class StateSemantics {
|
||||
static const authLoading = 'state_auth_loading';
|
||||
static const authError = 'state_auth_error';
|
||||
static const pageLoading = 'state_page_loading';
|
||||
|
||||
/// Generate ID for a snackbar.
|
||||
static String snackbar(String type) => 'snackbar_$type';
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Wraps a widget with semantic information for accessibility and automation.
|
||||
///
|
||||
/// Usage:
|
||||
/// ```dart
|
||||
/// SemanticWidget(
|
||||
/// id: ProfileSemantics.button,
|
||||
/// label: 'Open profile menu',
|
||||
/// child: IconButton(...),
|
||||
/// )
|
||||
/// ```
|
||||
///
|
||||
/// For buttons, use `button: true`. For other interactive elements,
|
||||
/// set the appropriate semantic properties.
|
||||
class SemanticWidget extends StatelessWidget {
|
||||
const SemanticWidget({
|
||||
super.key,
|
||||
required this.id,
|
||||
required this.child,
|
||||
this.label,
|
||||
this.hint,
|
||||
this.button = false,
|
||||
this.link = false,
|
||||
this.header = false,
|
||||
this.textField = false,
|
||||
this.enabled = true,
|
||||
this.selected,
|
||||
this.checked,
|
||||
this.value,
|
||||
this.excludeSemantics = false,
|
||||
});
|
||||
|
||||
/// Unique identifier for this widget, exposed via [SemanticsProperties.identifier].
|
||||
final String id;
|
||||
|
||||
/// The widget to wrap.
|
||||
final Widget child;
|
||||
|
||||
/// Accessibility label describing the widget.
|
||||
final String? label;
|
||||
|
||||
/// Hint text for screen readers.
|
||||
final String? hint;
|
||||
|
||||
/// Whether this widget represents a button.
|
||||
final bool button;
|
||||
|
||||
/// Whether this widget represents a link.
|
||||
final bool link;
|
||||
|
||||
/// Whether this widget represents a header.
|
||||
final bool header;
|
||||
|
||||
/// Whether this widget represents a text field.
|
||||
final bool textField;
|
||||
|
||||
/// Whether the widget is enabled.
|
||||
final bool enabled;
|
||||
|
||||
/// Whether the widget is selected (for toggle buttons, tabs).
|
||||
final bool? selected;
|
||||
|
||||
/// Whether the widget is checked (for checkboxes).
|
||||
final bool? checked;
|
||||
|
||||
/// Current value (for sliders, progress indicators).
|
||||
final String? value;
|
||||
|
||||
/// Whether to exclude child semantics.
|
||||
final bool excludeSemantics;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Semantics(
|
||||
identifier: id,
|
||||
label: label,
|
||||
hint: hint,
|
||||
button: button,
|
||||
link: link,
|
||||
header: header,
|
||||
textField: textField,
|
||||
enabled: enabled,
|
||||
selected: selected,
|
||||
checked: checked,
|
||||
value: value,
|
||||
excludeSemantics: excludeSemantics,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension to easily wrap any widget with semantic info.
|
||||
extension SemanticExtension on Widget {
|
||||
/// Wraps this widget with a semantic identifier.
|
||||
Widget withSemantics({
|
||||
required String id,
|
||||
String? label,
|
||||
String? hint,
|
||||
bool button = false,
|
||||
bool link = false,
|
||||
bool enabled = true,
|
||||
bool? selected,
|
||||
bool? checked,
|
||||
}) {
|
||||
return SemanticWidget(
|
||||
id: id,
|
||||
label: label,
|
||||
hint: hint,
|
||||
button: button,
|
||||
link: link,
|
||||
enabled: enabled,
|
||||
selected: selected,
|
||||
checked: checked,
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'app.dart';
|
||||
@@ -11,6 +13,12 @@ import 'version.g.dart';
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Enable semantics tree on web for accessibility and automation tools.
|
||||
// This exposes widget identifiers to browser automation (Puppeteer, etc.)
|
||||
if (kIsWeb) {
|
||||
SemanticsBinding.instance.ensureSemantics();
|
||||
}
|
||||
|
||||
// Use path-based URLs on web (no-op on mobile/desktop)
|
||||
configureUrlStrategy();
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tatlock_ui/core/semantics/semantic_ids.dart';
|
||||
|
||||
import 'panel_header.dart';
|
||||
|
||||
@@ -199,7 +200,12 @@ class _NavTile extends StatelessWidget {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
|
||||
return Padding(
|
||||
return Semantics(
|
||||
identifier: NavSemantics.item(item.id),
|
||||
label: item.label,
|
||||
button: true,
|
||||
selected: isSelected,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
child: Material(
|
||||
color: isSelected
|
||||
@@ -258,6 +264,7 @@ class _NavTile extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:tatlock_ui/core/auth/auth_provider.dart';
|
||||
import 'package:tatlock_ui/core/semantics/semantic_ids.dart';
|
||||
import 'package:tatlock_ui/core/theme/theme_provider.dart';
|
||||
import 'package:tatlock_ui/routing/app_router.dart';
|
||||
|
||||
@@ -20,7 +21,11 @@ class ProfileDropdown extends ConsumerWidget {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return authState.when(
|
||||
data: (auth) => PopupMenuButton<String>(
|
||||
data: (auth) => Semantics(
|
||||
identifier: ProfileSemantics.button,
|
||||
label: 'Profile menu',
|
||||
button: true,
|
||||
child: PopupMenuButton<String>(
|
||||
offset: const Offset(0, 48),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
@@ -69,9 +74,11 @@ class ProfileDropdown extends ConsumerWidget {
|
||||
const PopupMenuDivider(),
|
||||
|
||||
// Settings
|
||||
const PopupMenuItem<String>(
|
||||
PopupMenuItem<String>(
|
||||
value: 'settings',
|
||||
child: Row(
|
||||
child: Semantics(
|
||||
identifier: ProfileSemantics.settings,
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.settings_outlined, size: 20),
|
||||
SizedBox(width: 12),
|
||||
@@ -79,6 +86,7 @@ class ProfileDropdown extends ConsumerWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Theme submenu header
|
||||
PopupMenuItem<String>(
|
||||
@@ -97,6 +105,8 @@ class ProfileDropdown extends ConsumerWidget {
|
||||
PopupMenuItem<String>(
|
||||
value: 'theme_system',
|
||||
height: 40,
|
||||
child: Semantics(
|
||||
identifier: ProfileSemantics.themeSystem,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
@@ -119,11 +129,14 @@ class ProfileDropdown extends ConsumerWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Theme: Light
|
||||
PopupMenuItem<String>(
|
||||
value: 'theme_light',
|
||||
height: 40,
|
||||
child: Semantics(
|
||||
identifier: ProfileSemantics.themeLight,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
@@ -146,11 +159,14 @@ class ProfileDropdown extends ConsumerWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Theme: Dark
|
||||
PopupMenuItem<String>(
|
||||
value: 'theme_dark',
|
||||
height: 40,
|
||||
child: Semantics(
|
||||
identifier: ProfileSemantics.themeDark,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
@@ -173,14 +189,17 @@ class ProfileDropdown extends ConsumerWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const PopupMenuDivider(),
|
||||
|
||||
// Logout (only if authenticated)
|
||||
if (auth.isAuthenticated)
|
||||
const PopupMenuItem<String>(
|
||||
PopupMenuItem<String>(
|
||||
value: 'logout',
|
||||
child: Row(
|
||||
child: Semantics(
|
||||
identifier: ProfileSemantics.logout,
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.logout, size: 20),
|
||||
SizedBox(width: 12),
|
||||
@@ -188,6 +207,7 @@ class ProfileDropdown extends ConsumerWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
onSelected: (value) {
|
||||
switch (value) {
|
||||
@@ -204,6 +224,7 @@ class ProfileDropdown extends ConsumerWidget {
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
loading: () => const CircleAvatar(
|
||||
radius: 18,
|
||||
child: SizedBox(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tatlock_ui/core/semantics/semantic_ids.dart';
|
||||
|
||||
import 'profile_dropdown.dart';
|
||||
|
||||
@@ -127,6 +128,11 @@ class TopHeaderBar extends StatelessWidget {
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: Semantics(
|
||||
identifier: RoomTabSemantics.forIndex(index),
|
||||
label: room.label,
|
||||
button: true,
|
||||
selected: isSelected,
|
||||
child: Tooltip(
|
||||
message: room.label,
|
||||
child: IconButton(
|
||||
@@ -141,6 +147,7 @@ class TopHeaderBar extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 1.1.16+1
|
||||
version: 1.2.0+1
|
||||
|
||||
environment:
|
||||
sdk: ^3.10.4
|
||||
|
||||
Reference in New Issue
Block a user