Routes In Flutter

Routes In Flutter

Routes In Flutter

Routes mean collection of page in flutter application.

Routes use navigation (new page and back page) in flutter:

  1. Named: Navigator.pushNamed()
  2. Without named (call class name)

initalRoute: : ‘/’ indicator start the first screen. Your mind one of question ‘/’ what is this. This is first check routes: {} which is ‘/’ available then start the first screen.

Available: FirstScreen()

Not available ?:   Read the Router / Routing Setup

MaterialApp(
initialRoute: '/',
routes: {
    '/': (context) =>FirstScreen(),
    // When navigating to the "/second" route, build the SecondScreen widget.
    '/second': (context) =>SecondScreen(),
  },
);

Router/ Routing Setup

Material app provide the property onGenerateRoute.  onGenerateRoute return the Route<dynamic> and take parameter in RouteSettings

class Router {
  Route<dynamic>generateRoute(RouteSettings settings) {}
}

Not available ?:   here your question solved. If route name not available then call the default in switch case.

static Route<dynamic>generateRoute(RouteSettings settings) {
switch (settings.name) {
case '/':
returnMaterialPageRoute(builder: (_) => Home());
case '/feed':
returnMaterialPageRoute(builder: (_) => Feed());
default:
returnMaterialPageRoute(
builder: (_) => Scaffold(
body: Center(
child: Text('No route defined for ${settings.name}')),
                ));
    }
  }

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application