closeButton method
Finds a standard "close" button.
A common element on many user interfaces is the "close" button. This is the button which closes or cancels whatever it is attached to.
It is useful in tests to be able to find these buttons, both for tapping them or verifying their existence, but because different platforms and locales have different icons representing them with different labels and tooltips, it's not desirable to have to look them up by these attributes.
This finder uses the StandardComponentType enum to look for buttons that have the key associated with StandardComponentType.closeButton. If another widget is assigned that key, then it too will be considered an "official" close button in the widget tree, allowing this matcher to still find it even though it might use a different icon or tooltip.
Sample code
expect(find.closeButton(), findsOneWidget);
See also:
- StandardComponentType, the enum that enumerates components that are both common in user interfaces, but which also can vary slightly in presentation across different platforms, locales, and devices.
- CloseButton, the Flutter Material widget that represents a close button.
Implementation
Finder closeButton() {
return byKey(StandardComponentType.closeButton.key);
}