Skip to content

Instantly share code, notes, and snippets.

@yjbanov
Last active August 2, 2023 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yjbanov/26d2772e6a3afcdf0742436177599e2b to your computer and use it in GitHub Desktop.
Save yjbanov/26d2772e6a3afcdf0742436177599e2b to your computer and use it in GitHub Desktop.
Demonstrates an issue in semantic node focusability
import 'dart:ui_web' as ui_web;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:web/web.dart' as web;
void main() async {
_registerFactory();
runApp(const MyApp());
if (kIsWeb) {
SemanticsBinding.instance.ensureSemantics();
}
await Future<void>.delayed(const Duration(seconds: 2));
debugDumpSemanticsTree();
}
void _registerFactory() {
ui_web.platformViewRegistry.registerViewFactory('dom_button', (int viewId) {
final web.HTMLElement htmlElement =
web.document.createElement('button') as web.HTMLDivElement;
htmlElement.innerText = 'Button 2';
htmlElement.style
..setProperty('width', '100%')
..setProperty('height', '100%');
return htmlElement;
});
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Focusable platform view',
home: Scaffold(
body: SizedBox(
height: 100.0,
child: HtmlElementView(viewType: 'dom_button'),
),
),
);
}
}
@yjbanov
Copy link
Author

yjbanov commented Aug 2, 2023

The semantics tree for this UI:

SemanticsNode#0
 │ Rect.fromLTRB(0.0, 0.0, 3456.0, 1988.0)
 │
 └─SemanticsNode#1
   │ Rect.fromLTRB(0.0, 0.0, 1728.0, 994.0) scaled by 2.0x
   │ textDirection: ltr
   │
   └─SemanticsNode#2
     │ Rect.fromLTRB(0.0, 0.0, 1728.0, 994.0)
     │ sortKey: OrdinalSortKey#3af28(order: 0.0)
     │
     └─SemanticsNode#3
       │ Rect.fromLTRB(0.0, 0.0, 1728.0, 994.0)
       │ flags: scopesRoute
       │
       └─SemanticsNode#4
         │ Rect.fromLTRB(0.0, 0.0, 1728.0, 100.0)
         │ flags: isFocusable
         │
         └─SemanticsNode#5
             Rect.fromLTRB(0.0, 0.0, 1728.0, 100.0)
             platformViewId: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment