code method Null safety

Stream<CodeSearchResults> code(
  1. String query,
  2. {int? pages,
  3. int? perPage,
  4. String? language,
  5. String? filename,
  6. String? extension,
  7. String? user,
  8. String? org,
  9. String? repo,
  10. String? fork,
  11. String? path,
  12. String? size,
  13. bool inFile = true,
  14. bool inPath = false}
)

Search through code for a given query. By default you will get all search results if you consume all events on the returned stream. To limit results, set the pages and perPage parameters.

You can include any github qualifiers in the query directly or you can set some of the optional params to set the qualifiers For example, these do the same thing: code('awesome language:dart') and code('awesome', language: 'dart')

https://developer.github.com/v3/search/#search-code

Implementation

Stream<CodeSearchResults> code(
  String query, {
  int? pages,
  int? perPage,
  String? language,
  String? filename,
  String? extension,
  String? user,
  String? org,
  String? repo,
  String? fork,
  String? path,
  String? size,
  bool inFile = true,
  bool inPath = false,
}) {
  // Add qualifiers to the query
  // Known Issue: If a query already has a qualifier and the same
  // qualifier parameter is passed in, it will be duplicated.
  // Example: code('example repo:ex', repo: 'ex') will result in
  // a query of 'example repo:ex repo:ex'
  query += _searchQualifier('language', language);
  query += _searchQualifier('filename', filename);
  query += _searchQualifier('extension', extension);
  query += _searchQualifier('user', user);
  query += _searchQualifier('org', org);
  query += _searchQualifier('repo', repo);
  query += _searchQualifier('fork', fork);
  query += _searchQualifier('path', path);
  query += _searchQualifier('size', size);

  // build up the in: qualifier based on the 2 booleans
  var _in = '';
  if (inFile) {
    _in = 'file';
  }
  if (inPath) {
    if (_in.isEmpty) {
      _in = 'path';
    } else {
      _in = 'file,path';
    }
  }
  if (_in.isNotEmpty) {
    query += ' in:$_in';
  }

  final params = <String, dynamic>{};
  params['q'] = query;
  if (perPage != null) {
    params['per_page'] = perPage.toString();
  }

  return PaginationHelper(github)
      .fetchStreamed('GET', '/search/code', params: params, pages: pages)
      .map((r) => CodeSearchResults.fromJson(json.decode(r.body)));
}