backButton method

Finder backButton()

Finds a standard "back" button.

A common element on many user interfaces is the "back" button. This is the button which takes the user back to the previous page/screen/state.

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.backButton. If another widget is assigned that key, then it too will be considered an "official" back 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.backButton(), 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.
  • BackButton, the Flutter Material widget that represents the back button.

Implementation

Finder backButton() {
  return byKey(StandardComponentType.backButton.key);
}