surveyor
surveyor copied to clipboard
Surveyor cannot detect child/children, when the child/children are functions calls
The example below is from a Flutter Create submission, named ‘realx’.
In this example, the Row
widget takes two children, where each child widget is a function soundBtn()
that returns a GestureDetector
widget.
class HomeRoute extends StatelessWidget {
row(s1, s2, context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [soundBtn(s1, context), soundBtn(s2, context),],
);
}
soundBtn(sound, context) {
return GestureDetector(
onTap: () { Navigator.push(context, MaterialPageRoute(builder: (context) => PlayRoute(sound: sound))); },
child: Column(
children: [
Image.asset('assets/icons/$sound.png'),
Text(sound.toUpperCase(), style: TextStyle(color: Colors.white, fontSize: 16, letterSpacing: 3.0))
],
),
);
}
But in the Flutter Outline as well as in the surveyor's 2-gram output file, this Row
widget doesn’t seem to carry any children widget.
Flutter Outline (partially captured):
Surveyor output:
Column -> Image, 1
Column -> Text, 2
GestureDetector -> Column, 1
GestureDetector -> PlayRoute, 1
null -> GestureDetector, 1
null -> Row, 1
. . .
This makes it hard to analyze the characteristics of leaf widgets. I’d like the surveyor to take care of this case.
However, if this is a non-trivial change, as a minimal effort, we could consider adding -> unknown
to the 2-gram output file, whenever an empty child or children appears.
For instance, if the analyzer says that the Row
widget is a leaf, but if it contains children
keyword in the code, add Row -> unknown
to the 2-gram output. In that way we can at least know that the Row
is not a leaf widget.