A brief introduction to the initialRoute and onGenerateRoute properties of the basic component MaterialAPP of Flutter app home page

A brief introduction to the initialRoute and onGenerateRoute properties of the basic component MaterialAPP of Flutter app home page


initialRoute The
initialRoute attribute is used to specify the initial route when the application starts, that is, the first page jumped after the application starts. Even if the home attribute value is set in the application, the first page after startup is also the page specified by the initialRoute route. The value of this property is of type String.
During application development, at least one of the three properties of home, initialRoute and onGenerateRoute must be set.

When the iniislRoute is not set, the first page after opening the APP is specified by home
insert image description here

insert image description here
However, after the initialRoute specifies the route, the first thing to start is the page specified by the initialRoute. The initialRoute has priority.
insert image description here

Open the first page of the app:

insert image description here
OnGenerateRoute
When the name of the original home or initialRoute route is wrong or empty, or the following route cannot find the page, onGenerateRoute forces the creation of a route page, which is connected to the new route page by default

onGenerateRoute:(setting){
    
    
          return PageRouteBuilder(pageBuilder: (BuildContext, _,__){
    
    
            return yangxdpage();
          });
      } ,

Guess you like

Origin blog.csdn.net/qq_43336158/article/details/123432944