flutter achieve page jump two routes

1 . Anonymous routing push, directly 
void nextPage () {the async   Final Result = the await Navigator.push (context, MaterialPageRoute (Builder: (BuildContext context) {     
return NextPage ( "Pass the params to Next Page" ); // Constructor transfer parameter   }));
  // return result page result
}
Navigator.pop (context, "return value to last page"); // page return

2. Name the route pushNamed, first register and then use
void main () => runApp ( MyApp ()); // call the function of writing a single line 
class the extends StatelessWidget the MyApp {
@override
the Widget Build (BuildContext context) {
return MaterialApp (
title: "My the App the Title",
Theme: ThemeData (primaryColor: Colors.green),
// Home: RandomWord (), set the way home a
initialRoute: "home_route", // Home settings way two
routes: {// routing registry
"next_page": (BuildContext context) {
return NextPage (ModalRoute .of (context) .settings.arguments);
},
"home_route": (BuildContext context) => RandomWord (),
},
// onGenerateRoute: // page interception process
// onUnknownRoute: // page jump error
);
}
}

void nextPage() async{
final result = await Navigator.pushNamed(context, "next_page",arguments: "pass params to next page");
//result页面返回结果
}

// next_page acquisition parameters on a page transfer from the method: ModalRoute.of (context) .settings.arguments


 

Guess you like

Origin www.cnblogs.com/yongfengnice/p/12112287.html