In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, the editor will share with you the relevant knowledge about how to achieve Flutter Navigator routing parameters. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
There are two types of default navigation in Flutter, named routes and build routes.
I. named routing to pass parameters
Define the routing table at the application entrance
Class MyApp extends StatelessWidget {const MyApp ({Key? Key}): super (key: key); @ override Widget build (BuildContext context) {return MaterialApp (debugShowCheckedModeBanner: false, / / hide the debug title in the preview: 'Flutter Demo', routes: {' /': (context) = > const HomePage (), "menu": (context) = > const MenuPage ()},);}} / / define HomePageclass HomePage extends StatelessWidget {const HomePage ({Key? Key}): super (key: key); @ override Widget build (BuildContext context) {return Scaffold (appBar: AppBar (title: const Text ("login"),), body: ElevatedButton (onPressed: () async {/ / implement route jump var result = await Navigator.pushNamed (context, 'menu', arguments: {' name': 'title'}) Print (result);}, child: const Text ('login'),);}} / / define MenuPageclass MenuPage extends StatelessWidget {const MenuPage ({Key? Key}): super (key: key); @ override / / receive and transmit parameters Widget build (BuildContext context) {dynamic argumentsData = ModalRoute.of (context)? .settings.settings; return Scaffold (appBar: AppBar (title: Text ('menu' + argumentsData.toString (),), body: ElevatedButton (onPressed: () {Navigator.pop (context, {'name': "Navigator.pop parameters"})) }, child: const Text ("return"),);}} II. Construct routing parameters
When you jump to a MenuPage page from a HomePage page, take the parameters with you
The first way: / / define HomePageclass HomePage extends StatelessWidget {const HomePage ({Key? Key}): super (key: key) @ override Widget build (BuildContext context) {return Scaffold (appBar: AppBar (title: const Text),), body: ElevatedButton (onPressed: () {/ / implement route jump Navigator.push (context) MaterialPageRoute (builder: (context) = > const MenuPage (title: 'menu 123,), / / pages to be redirected), / / modify route name, information, etc.) }, child: const Text ('login'),);}} / define MenuPageclass MenuPage extends StatelessWidget {/ / define the received field final String title; const MenuPage ({Key? Key, required this.title}): super (key: key); @ override Widget build (BuildContext context) {return Scaffold (appBar: AppBar (title: Text (title),), body: ElevatedButton (onPressed: () {Navigator.pop (context);}, child: const Text ("return"),) }} the second way: / / define HomePageclass HomePage extends StatelessWidget {const HomePage ({Key? Key}): super (key: key) @ override Widget build (BuildContext context) {return Scaffold (appBar: AppBar (title: const Text),), body: ElevatedButton (onPressed: () {/ / implement route jump Navigator.push (context, MaterialPageRoute (builder: (context) = > const MenuPage ()) / / modify the name and information of the route, such as settings: const RouteSettings (name: 'menu', arguments: {"name": '123'}) / / pages to be redirected),) }, child: const Text ('login'),);}} / / define MenuPageclass MenuPage extends StatelessWidget {const MenuPage ({Key? Key}): super (key: key); @ override / / receive and transmit parameters Widget build (BuildContext context) {dynamic argumentsData = ModalRoute.of (context)? .settings.settings; return Scaffold (appBar: AppBar (title: Text ('menu' + argumentsData.toString (),), body: ElevatedButton (onPressed: () {Navigator.pop (context)) }, child: const Text ("return"),);}}
When you return to the HomePage page from the MenuPage page, take the parameters
/ / define HomePageclass HomePage extends StatelessWidget {const HomePage ({Key? Key}): super (key: key) @ override Widget build (BuildContext context) {return Scaffold (appBar: AppBar (title: const Text),), body: ElevatedButton (onPressed: () async {/ / implement route jump var result = await Navigator.push (context, MaterialPageRoute (builder: (context) = > const MenuPage (),) ) Print (result);}, child: const Text ('login'),);}} / / define MenuPageclass MenuPage extends StatelessWidget {const MenuPage ({Key? Key}): super (key: key); @ override / / receive and pass parameters Widget build (BuildContext context) {return Scaffold (appBar: AppBar (title: const Text ('menu'),), body: ElevatedButton (onPressed: () {Navigator.pop (context, {'name': "Navigator.pop pass parameters"}) }, child: const Text ("return"),);}} above is all the content of the article "how to implement Flutter Navigator routing parameters". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 230
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.