createFinder function

  1. @visibleForTesting
Finder createFinder(
  1. dynamic matching
)

Creates a Finder from matching.

This function maps types onto Flutter finders.

Usage

Usually, you won't use this function directly. Instead, you'll use PatrolTester.call and PatrolFinder.$, like this:

patrolTest(
   'increase counter text',
   ($) async {
     // calls createFinder method under the hood
     await $(Scaffold).$(#passwordTextField).enterText('my password');
   },
);

What does this method accept?

The Finder that this method returns depends on the type of matching. Supported types of matching are:

See also:

Implementation

@visibleForTesting
Finder createFinder(dynamic matching) {
  if (matching is Type) {
    return find.byType(matching);
  }

  if (matching is Key) {
    return find.byKey(matching);
  }

  if (matching is Symbol) {
    return find.byKey(Key(matching.name));
  }

  if (matching is String) {
    return find.text(matching, findRichText: true);
  }

  if (matching is Pattern) {
    return find.textContaining(matching, findRichText: true);
  }

  if (matching is IconData) {
    return find.byIcon(matching);
  }

  if (matching is PatrolFinder) {
    return matching.finder;
  }

  if (matching is Finder) {
    return matching;
  }

  if (matching is Widget) {
    return find.byWidget(matching);
  }

  throw ArgumentError(
    'Argument of type ${matching.runtimeType} is not supported. '
    'Supported types: Type, Key, Symbol, String, Pattern, IconData, '
    'PatrolFinder, Finder, Widget',
  );
}