@@ -238,6 +238,13 @@ int getChildLayerCount(OffsetLayer layer) {
238
238
return count;
239
239
}
240
240
241
+ extension TextFromString on String {
242
+ @widgetFactory
243
+ Widget text () {
244
+ return Text (this );
245
+ }
246
+ }
247
+
241
248
void main () {
242
249
_TestWidgetInspectorService .runTests ();
243
250
}
@@ -944,19 +951,20 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
944
951
945
952
testWidgets ('WidgetInspectorService creationLocation' , (WidgetTester tester) async {
946
953
await tester.pumpWidget (
947
- const Directionality (
954
+ Directionality (
948
955
textDirection: TextDirection .ltr,
949
956
child: Stack (
950
957
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 ( ),
954
961
],
955
962
),
956
963
),
957
964
);
958
965
final Element elementA = find.text ('a' ).evaluate ().first;
959
966
final Element elementB = find.text ('b' ).evaluate ().first;
967
+ final Element elementC = find.text ('c' ).evaluate ().first;
960
968
961
969
service.disposeAllGroups ();
962
970
service.resetPubRootDirectories ();
@@ -979,14 +987,28 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
979
987
final int columnB = creationLocationB['column' ]! as int ;
980
988
final String ? nameB = creationLocationB['name' ] as String ? ;
981
989
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
+
982
1001
expect (fileA, endsWith ('widget_inspector_test.dart' ));
983
1002
expect (fileA, equals (fileB));
1003
+ expect (fileA, equals (fileC));
984
1004
// We don't hardcode the actual lines the widgets are created on as that
985
1005
// would make this test fragile.
986
1006
expect (lineA + 1 , equals (lineB));
1007
+ expect (lineB + 1 , equals (lineC));
987
1008
// Column numbers are more stable than line numbers.
988
- expect (columnA, equals (15 ));
1009
+ expect (columnA, equals (21 ));
989
1010
expect (columnA, equals (columnB));
1011
+ expect (columnC, equals (19 ));
990
1012
}, skip: ! WidgetInspectorService .instance.isWidgetCreationTracked ()); // [intended] Test requires --track-widget-creation flag.
991
1013
992
1014
testWidgets ('WidgetInspectorService setSelection notifiers for an Element' ,
0 commit comments