finderForTarget function

Finder finderForTarget(
  1. dynamic target
)

Resolves a verb's polymorphic target to a Finder.

A Finder passes through, a String is visible text, a Key, an IconData and a Type mean the obvious thing, and a Target says the things that vocabulary cannot.

dynamic is a deliberate exception to the house no-dynamic preference: tap('NEXT') / tap(Icons.add) / tap(Keys.next) read too well to give up.

Implementation

Finder finderForTarget(dynamic target) {
  return switch (target) {
    Finder() => target,
    Target() => target.toFinder(),
    String() => find.text(target, findRichText: true),
    Key() => find.byKey(target),
    IconData() => find.byIcon(target),
    Type() => find.byType(target),
    _ => throw ArgumentError(
      'a scenario target is a Finder, a String, a Key, an IconData, a Type '
      'or a Target, got ${target.runtimeType}',
    ),
  };
}