20. Flutter - Routing (Loading Different Page Widgets)
A route is a map that holds a key (which defines a dart file) and a value (which is a function that loads a widget in the dart file). Defining a route: routes: { "/" : (context) => {WIDGET()}, "/SECONDFILE: (context) = > {WIDGET()}, } // the first route must be empty because it means it is the first widget to display at the start. // requires a context parameter in a route function. Don't need to change. Can override the first route with a property: initialRoute: "/ROUTETOBESTART", Navigating between pages/widgets: Navigator.pushNamed(context, "/ROUTETOGOTO"); // Usage: place this function inside a onPressed function. // pushes a new page onto the current page. // if new page has a appBar, the appBar will automatically have a back button to go back to current page. // Like push and pop.