@@ -238,6 +238,13 @@ int getChildLayerCount(OffsetLayer layer) {
238238 return count;
239239}
240240
241+ extension TextFromString on String {
242+ @widgetFactory
243+ Widget text () {
244+ return Text (this );
245+ }
246+ }
247+
241248void main () {
242249 _TestWidgetInspectorService .runTests ();
243250}
@@ -944,19 +951,20 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
944951
945952 testWidgets ('WidgetInspectorService creationLocation' , (WidgetTester tester) async {
946953 await tester.pumpWidget (
947- const Directionality (
954+ Directionality (
948955 textDirection: TextDirection .ltr,
949956 child: Stack (
950957 children: < Widget > [
951- Text ('a' ),
952- Text ('b' , textDirection: TextDirection .ltr),
953- Text ( 'c' , textDirection : TextDirection .ltr ),
958+ const Text ('a' ),
959+ const Text ('b' , textDirection: TextDirection .ltr),
960+ 'c' . text ( ),
954961 ],
955962 ),
956963 ),
957964 );
958965 final Element elementA = find.text ('a' ).evaluate ().first;
959966 final Element elementB = find.text ('b' ).evaluate ().first;
967+ final Element elementC = find.text ('c' ).evaluate ().first;
960968
961969 service.disposeAllGroups ();
962970 service.resetPubRootDirectories ();
@@ -979,14 +987,28 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
979987 final int columnB = creationLocationB['column' ]! as int ;
980988 final String ? nameB = creationLocationB['name' ] as String ? ;
981989 expect (nameB, equals ('Text' ));
990+
991+ service.setSelection (elementC, 'my-group' );
992+ final Map <String , Object ?> jsonC = json.decode (service.getSelectedWidget (null , 'my-group' )) as Map <String , Object ?>;
993+ final Map <String , Object ?> creationLocationC = jsonC['creationLocation' ]! as Map <String , Object ?>;
994+ expect (creationLocationC, isNotNull);
995+ final String fileC = creationLocationC['file' ]! as String ;
996+ final int lineC = creationLocationC['line' ]! as int ;
997+ final int columnC = creationLocationC['column' ]! as int ;
998+ final String ? nameC = creationLocationC['name' ] as String ? ;
999+ expect (nameC, equals ('TextFromString|text' ));
1000+
9821001 expect (fileA, endsWith ('widget_inspector_test.dart' ));
9831002 expect (fileA, equals (fileB));
1003+ expect (fileA, equals (fileC));
9841004 // We don't hardcode the actual lines the widgets are created on as that
9851005 // would make this test fragile.
9861006 expect (lineA + 1 , equals (lineB));
1007+ expect (lineB + 1 , equals (lineC));
9871008 // Column numbers are more stable than line numbers.
988- expect (columnA, equals (15 ));
1009+ expect (columnA, equals (21 ));
9891010 expect (columnA, equals (columnB));
1011+ expect (columnC, equals (19 ));
9901012 }, skip: ! WidgetInspectorService .instance.isWidgetCreationTracked ()); // [intended] Test requires --track-widget-creation flag.
9911013
9921014 testWidgets ('WidgetInspectorService setSelection notifiers for an Element' ,
0 commit comments