ViewControllers

Domains: Flutter

What is the equivalent to ViewController in Flutter?

In iOS, a ViewController represents a portion of user interface, most commonly used for a screen or section. These are composed together to build complex user interfaces, and help scale your application’s UI. In Flutter, this job falls to Widgets. As mentioned in the Navigation section, screens in Flutter are represented by Widgets since “everything is a widget!” Use a Navigator to move between different Routes that represent different screens or pages, or maybe different states or renderings of the same data.

How do I listen to iOS lifecycle events?

In iOS, you can override methods to the ViewController to capture lifecycle methods for the view itself, or register lifecycle callbacks in the AppDelegate. In Flutter you have neither concept, but you can instead listen to lifecycle events by hooking into the WidgetsBinding observer and listening to the didChangeAppLifecycleState() change event.

The observable lifecycle events are:

  • inactive — The application is in an inactive state and is not receiving user input. This event only works on iOS, as there is no equivalent event on Android.
  • paused — The application is not currently visible to the user, is not responding to user input, but is running in the background.
  • resumed — The application is visible and responding to user input.
  • suspending — The application is suspended momentarily. The iOS platform has no equivalent event.

For more details on the meaning of these states, see AppLifecycleStatus documentation.

Similar pages

Page structure
Terms

Flutter

Widget

Navigator

Route

State