from method Null safety

SearchQueryBuilder from(
  1. String query,
  2. SearchQueryType queryType,
  3. {SearchMessageType? messageType,
  4. DateTime? since,
  5. DateTime? before,
  6. DateTime? sentSince,
  7. DateTime? sentBefore}
)

Helper to create a common search query. query contains the search text, define where to search with the queryType. Optionally you can also define what kind of messages to search with the messageType, the internal date since a message has been received with since, the internal date before a message has been received with before, the internal date since a message has been sent with sentSince, the internal date before a message has been sent with sentBefore,

Implementation

static SearchQueryBuilder from(String query, SearchQueryType queryType,
    {SearchMessageType? messageType,
    DateTime? since,
    DateTime? before,
    DateTime? sentSince,
    DateTime? sentBefore}) {
  final builder = SearchQueryBuilder();
  if (query.isNotEmpty) {
    if (_TextSearchTerm.containsNonAsciiCharacters(query)) {
      builder.add(const SearchTermCharsetUf8());
    }
    switch (queryType) {
      case SearchQueryType.subject:
        builder.add(SearchTermSubject(query));
        break;
      case SearchQueryType.from:
        builder.add(SearchTermFrom(query));
        break;
      case SearchQueryType.to:
        builder.add(SearchTermTo(query));
        break;
      case SearchQueryType.allTextHeaders:
        builder.add(SearchTermText(query));
        break;
      case SearchQueryType.body:
        builder.add(SearchTermBody(query));
        break;
      case SearchQueryType.fromOrSubject:
        builder.add(
            SearchTermOr(SearchTermFrom(query), SearchTermSubject(query)));
        break;
      case SearchQueryType.toOrSubject:
        builder
            .add(SearchTermOr(SearchTermTo(query), SearchTermSubject(query)));
        break;
      case SearchQueryType.fromOrTo:
        builder.add(SearchTermOr(SearchTermFrom(query), SearchTermTo(query)));
        break;
    }
  }

  if (messageType != null) {
    switch (messageType) {
      case SearchMessageType.all:
        // ignore
        break;
      case SearchMessageType.flagged:
        builder.add(SearchTermFlagged());
        break;
      case SearchMessageType.unflagged:
        builder.add(SearchTermUnflagged());
        break;
      case SearchMessageType.seen:
        builder.add(SearchTermSeen());
        break;
      case SearchMessageType.unseen:
        builder.add(SearchTermUnseen());
        break;
      case SearchMessageType.deleted:
        builder.add(SearchTermDeleted());
        break;
      case SearchMessageType.undeleted:
        builder.add(SearchTermUndeleted());
        break;
      case SearchMessageType.draft:
        builder.add(SearchTermDraft());
        break;
      case SearchMessageType.undraft:
        builder.add(SearchTermUndraft());
        break;
    }
  }
  if (before != null) {
    builder.add(SearchTermBefore(before));
  }
  if (since != null) {
    builder.add(SearchTermSince(since));
  }
  if (sentBefore != null) {
    builder.add(SearchTermSentBefore(sentBefore));
  }
  if (sentSince != null) {
    builder.add(SearchTermSentSince(sentSince));
  }
  return builder;
}