pq / surveyor

📐 Tools for surveying Dart packages
Apache License 2.0
53 stars 12 forks source link

Surveyor cannot detect child/children, when the child/children are functions calls #6

Open jayoung-lee opened 5 years ago

jayoung-lee commented 5 years ago

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): image

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.