Widget _getElementStats()

in packages/sampler/lib/main.dart [164:234]


  Widget _getElementStats(SourceElement element) {
    if (element.comment.isEmpty) {
      return Text.rich(
        TextSpan(
          children: <InlineSpan>[
            TextSpan(
              text: <String>[
                'No documentation or samples.',
                if (element.override) " No worries, it's an override.",
              ].join(''),
              style: TextStyle(
                color: element.override ? null : Colors.red,
                fontStyle: element.override ? null : FontStyle.italic,
                fontWeight: element.override ? null : FontWeight.bold,
              ),
            ),
          ],
        ),
      );
    }
    final int total = element.sampleCount;
    final int dartpads = element.dartpadSampleCount;
    final int snippets = element.snippetCount;
    final int applications = element.applicationSampleCount;
    final bool allOneKind =
        total == snippets || total == applications || total == dartpads;
    final String sampleCount = <String>[
      if (!allOneKind)
        '${Model.instance.samples.length} sample${Model.instance.samples.length != 1 ? 's' : ''} total',
      if (snippets > 0) '$snippets snippet${snippets != 1 ? 's' : ''}',
      if (applications > 0)
        '$applications application sample${applications != 1 ? 's' : ''}',
      if (dartpads > 0) '$dartpads dartpad sample${dartpads != 1 ? 's' : ''}'
    ].join(', ');
    final int wordCount = element.wordCount;
    final int lineCount = element.lineCount;
    final int linkCount = element.referenceCount;
    final String description = <String>[
      'Documentation has $wordCount ${wordCount == 1 ? 'word' : 'words'} on ',
      '$lineCount ${lineCount == 1 ? 'line' : 'lines'}',
      if (linkCount > 0 && element.hasSeeAlso) ', ',
      if (linkCount > 0 && !element.hasSeeAlso) ' and ',
      if (linkCount > 0)
        'refers to $linkCount other ${linkCount == 1 ? 'symbol' : 'symbols'}',
      if (linkCount > 0 && element.hasSeeAlso) ', and ',
      if (linkCount == 0 && element.hasSeeAlso) 'and ',
      if (element.hasSeeAlso) 'has a "See also:" section',
      '.',
    ].join('');
    return Text.rich(
      TextSpan(children: <InlineSpan>[
        if (total == 0)
          const TextSpan(
            text: 'Has no sample code. ',
            style: TextStyle(
              color: Colors.red,
              fontStyle: FontStyle.italic,
            ),
          ),
        if (total > 0)
          TextSpan(
            text: 'Has $sampleCount. ',
            style: const TextStyle(
              color: Colors.green,
              fontStyle: FontStyle.italic,
            ),
          ),
        TextSpan(text: description),
      ]),
    );
  }