findInnerPlatformTextField static method
Finds and returns the platform textfield within a SuperTextField.
By default, this method expects a single SuperTextField in the widget tree and
finds it byType. To specify one SuperTextField among many, pass a superTextFieldFinder.
Implementation
static Finder findInnerPlatformTextField([Finder? superTextFieldFinder]) {
final rootFieldFinder = superTextFieldFinder ?? find.byType(SuperTextField);
final rootMatches = rootFieldFinder.evaluate();
if (rootMatches.isEmpty) {
throw Exception("Couldn't find a super text field variant with the given finder: $rootFieldFinder");
}
if (rootMatches.length > 1) {
throw Exception("Found more than 1 super text field match with finder: $rootFieldFinder");
}
final rootMatch = rootMatches.single.widget;
if (rootMatch is! SuperTextField) {
// The match isn't a generic SuperTextField. Assume that it's a platform
// specific super text field, which is what we're looking for. Return it.
return rootFieldFinder;
}
final desktopFieldCandidates =
find.descendant(of: rootFieldFinder, matching: find.byType(SuperDesktopTextField)).evaluate();
if (desktopFieldCandidates.isNotEmpty) {
return find.descendant(of: rootFieldFinder, matching: find.byType(SuperDesktopTextField));
}
final androidFieldCandidates =
find.descendant(of: rootFieldFinder, matching: find.byType(SuperAndroidTextField)).evaluate();
if (androidFieldCandidates.isNotEmpty) {
return find.descendant(of: rootFieldFinder, matching: find.byType(SuperAndroidTextField));
}
final iosFieldCandidates =
find.descendant(of: rootFieldFinder, matching: find.byType(SuperIOSTextField)).evaluate();
if (iosFieldCandidates.isNotEmpty) {
return find.descendant(of: rootFieldFinder, matching: find.byType(SuperIOSTextField));
}
throw Exception(
"Couldn't find the platform-specific super text field within the root SuperTextField. Root finder: $rootFieldFinder");
}