[{"data":1,"prerenderedAt":5987},["ShallowReactive",2],{"navigation_docs_en":3,"-en-flutter-for-jobseekers-navigation-and-routing":95,"-en-flutter-for-jobseekers-navigation-and-routing-surround":5982},[4,16],{"title":5,"icon":6,"path":7,"stem":8,"children":9,"page":15},"Getting Started","i-lucide-rocket","\u002Fen\u002Fgetting-started","en\u002F1.getting-started",[10],{"title":11,"path":12,"stem":13,"icon":14},"Introduction","\u002Fen\u002Fgetting-started\u002Fintroduction","en\u002F1.getting-started\u002F1.introduction","i-lucide-house",false,{"title":17,"icon":18,"path":19,"stem":20,"children":21,"page":15},"Flutter for Jobseekers","i-lucide-briefcase","\u002Fen\u002Fflutter-for-jobseekers","en\u002F2.flutter-for-jobseekers",[22,27,32,37,42,47,52,57,62,67,72,77,82,86,91],{"title":23,"path":24,"stem":25,"icon":26},"Introduction to Flutter","\u002Fen\u002Fflutter-for-jobseekers\u002Fintroduction-to-flutter","en\u002F2.flutter-for-jobseekers\u002F1.introduction-to-flutter","i-lucide-history",{"title":28,"path":29,"stem":30,"icon":31},"Market Opportunities for Flutter Developers","\u002Fen\u002Fflutter-for-jobseekers\u002Fmarket-opportunities","en\u002F2.flutter-for-jobseekers\u002F2.market-opportunities","i-lucide-trending-up",{"title":33,"path":34,"stem":35,"icon":36},"Installing Flutter and Configuring Your IDE","\u002Fen\u002Fflutter-for-jobseekers\u002Finstalling-flutter","en\u002F2.flutter-for-jobseekers\u002F3.installing-flutter","i-lucide-wrench",{"title":38,"path":39,"stem":40,"icon":41},"Introduction to Widgets","\u002Fen\u002Fflutter-for-jobseekers\u002Fintroduction-to-widgets","en\u002F2.flutter-for-jobseekers\u002F4.introduction-to-widgets","i-lucide-blocks",{"title":43,"path":44,"stem":45,"icon":46},"Handling User Input","\u002Fen\u002Fflutter-for-jobseekers\u002Fhandling-user-input","en\u002F2.flutter-for-jobseekers\u002F5.handling-user-input","i-lucide-text-cursor-input",{"title":48,"path":49,"stem":50,"icon":51},"Using 3rd Party Libraries and External Assets","\u002Fen\u002Fflutter-for-jobseekers\u002Fusing-packages-and-assets","en\u002F2.flutter-for-jobseekers\u002F6.using-packages-and-assets","i-lucide-package",{"title":53,"path":54,"stem":55,"icon":56},"Working with APIs and Asynchronous Operations","\u002Fen\u002Fflutter-for-jobseekers\u002Fworking-with-apis-and-async","en\u002F2.flutter-for-jobseekers\u002F7.working-with-apis-and-async","i-lucide-cloud-download",{"title":58,"path":59,"stem":60,"icon":61},"Navigation and Routing","\u002Fen\u002Fflutter-for-jobseekers\u002Fnavigation-and-routing","en\u002F2.flutter-for-jobseekers\u002F8.navigation-and-routing","i-lucide-route",{"title":63,"path":64,"stem":65,"icon":66},"State Management and the BLoC","\u002Fen\u002Fflutter-for-jobseekers\u002Fstate-management-and-bloc","en\u002F2.flutter-for-jobseekers\u002F9.state-management-and-bloc","i-lucide-boxes",{"title":68,"path":69,"stem":70,"icon":71},"Reactivity and Platform-Specific Considerations","\u002Fen\u002Fflutter-for-jobseekers\u002Freactivity-and-platforms","en\u002F2.flutter-for-jobseekers\u002F910.reactivity-and-platforms","i-lucide-monitor-smartphone",{"title":73,"path":74,"stem":75,"icon":76},"Debugging, Troubleshooting, and Performance Considerations","\u002Fen\u002Fflutter-for-jobseekers\u002Fdebugging-troubleshooting-performance","en\u002F2.flutter-for-jobseekers\u002F911.debugging-troubleshooting-performance","i-lucide-bug",{"title":78,"path":79,"stem":80,"icon":81},"Creating Your First Application","\u002Fen\u002Fflutter-for-jobseekers\u002Fcreating-your-first-application","en\u002F2.flutter-for-jobseekers\u002F912.creating-your-first-application","i-lucide-cloud-sun",{"title":83,"path":84,"stem":85,"icon":18},"Finding Flutter Jobs","\u002Fen\u002Fflutter-for-jobseekers\u002Ffinding-flutter-jobs","en\u002F2.flutter-for-jobseekers\u002F913.finding-flutter-jobs",{"title":87,"path":88,"stem":89,"icon":90},"Preparing for and Succeeding in the Job Interview","\u002Fen\u002Fflutter-for-jobseekers\u002Fpreparing-for-the-job-interview","en\u002F2.flutter-for-jobseekers\u002F914.preparing-for-the-job-interview","i-lucide-messages-square",{"title":92,"path":93,"stem":94,"icon":61},"Your Road Ahead","\u002Fen\u002Fflutter-for-jobseekers\u002Fyour-road-ahead","en\u002F2.flutter-for-jobseekers\u002F915.your-road-ahead",{"id":96,"title":58,"body":97,"description":5975,"extension":5976,"links":5977,"meta":5978,"navigation":5979,"path":59,"seo":5980,"stem":60,"__hash__":5981},"docs_en\u002Fen\u002F2.flutter-for-jobseekers\u002F8.navigation-and-routing.md",{"type":98,"value":99,"toc":5927},"minimark",[100,119,131,165,170,220,224,232,242,247,250,275,283,287,294,331,349,352,356,366,394,405,409,448,460,464,474,715,735,770,781,800,808,811,840,843,846,875,927,931,945,981,995,1030,1034,1048,1061,1080,1087,1106,1133,1143,1147,1154,1164,1167,1192,1204,1216,1221,1226,1229,1236,1239,1256,1259,1263,1266,1327,1349,1399,1407,1414,1428,1534,1537,1591,1607,1613,1625,1773,1790,1828,1837,1941,1968,1986,1992,2002,2005,2008,2023,2027,2034,2128,2139,2251,2255,2269,2275,2294,2298,2304,2345,2363,2403,2409,2453,2474,2481,2495,2498,2501,2517,2525,2528,2790,2797,2816,2841,2848,2854,2860,2875,2878,2881,2905,2908,2914,2920,2927,2937,2941,2944,2965,2969,2976,2979,3443,3499,3510,3542,3546,3555,3640,3643,3649,3663,3752,3769,3774,4195,4201,4281,4292,4362,4367,4376,4562,4575,4606,4610,4617,4685,4688,4692,4695,4839,4847,4857,4863,4866,4869,4880,4883,4886,5604,5630,5641,5651,5665,5669,5672,5675,5679,5753,5757,5771,5774,5803,5817,5821,5923],[101,102,103,107],"u-page-hero",{},[104,105,58],"template",{"v-slot:title":106},"",[104,108,109,110,114,115,118],{"v-slot:description":106},"Most modern applications have their content organized in multiple, distinct screens, which break up a workflow from being a single and monolithic behemoth into smaller and purpose-driven views. The concept of sending a user from one screen to another is ",[111,112,113],"strong",{},"routing",", which we accomplish using the action of ",[111,116,117],{},"navigation",". A user navigates to a new screen, where the application then routes them to it.",[120,121,122,123,126,127,130],"p",{},"In this chapter, we are going to explore how navigation and routing work in Flutter. We will explore ",[111,124,125],{},"Navigator 1.0",", the simplest and most approachable method of routing (albeit with its own drawbacks and limitations), then we will investigate the newer and more powerful ",[111,128,129],{},"Navigator 2.0",". Finally, we will explore a package that seeks to make Navigator 2.0 as easy to use as possible.",[132,133,134,137,138,142,143,146,147,156,157,160,161,164],"note",{},[111,135,136],{},"Companion code:"," the publisher's repository holds this chapter's code as ",[139,140,141],"code",{},"Example 8.1","–",[139,144,145],{},"Example 8.29"," in the ",[148,149,153],"a",{"href":150,"rel":151},"https:\u002F\u002Fgithub.com\u002Fbpbpublications\u002FFlutter-for-Jobseekers\u002Ftree\u002Fmain\u002FChapter%2008",[152],"nofollow",[139,154,155],{},"Chapter 08"," folder; most examples are the whole program up to that point, so each code block below is labelled with the first example that contains it. Blocks without a label have no counterpart in the repository. The repository's constructors use the older ",[139,158,159],{},"{Key? key}) : super(key: key)"," form instead of ",[139,162,163],{},"{super.key}",", and it has conversion glitches of its own, so the code on this page follows the book (BPB Publications, n.d.).",[166,167,169],"h2",{"id":168},"chapter-overview","Chapter overview",[171,172,173,206,211],"card-group",{},[174,175,178],"card",{"icon":176,"title":177},"i-lucide-list","Structure",[179,180,181,185,188,191,194,197,200,203],"ul",{},[182,183,184],"li",{},"A general discussion of navigation and routing concepts",[182,186,187],{},"An introduction to Navigator 1.0",[182,189,190],{},"Routing using named routes",[182,192,193],{},"Passing arguments into a route",[182,195,196],{},"Returning data from a screen",[182,198,199],{},"Animating a widget from one route to another",[182,201,202],{},"Introduction to Navigator 2.0 — the Router API",[182,204,205],{},"Using packages to help with routing",[174,207,210],{"icon":208,"title":209},"i-lucide-target","Objectives","After finishing this chapter, you will be able to accurately describe the concepts behind navigation and routing. You will be able to use this knowledge to build a simple application that uses Flutter's most basic navigation system, then learn how to use the newer and more powerful system which was introduced later. Finally, you will learn how to simplify a more complex routing scenario by using a package from Pub.",[174,212,215,216,219],{"icon":213,"title":214},"i-lucide-folder-code","Runnable example","The chapter's Navigator 1.0 demos, the Router API contacts app and the Beamer contacts app are also available as a runnable project with tests in ",[139,217,218],{},"examples\u002Fflutter_for_jobseekers_ch08\u002F",". The code on this page is shown as the book prints it, with conversion glitches fixed.",[166,221,223],{"id":222},"general-discussion-of-navigation-and-routing-concepts","General discussion of navigation and routing concepts",[120,225,226,227,231],{},"As we briefly touched on in the introduction, applications respond to a user's intent to navigate by routing them to the place they would like to go. If you have ever clicked a link on a website, you will know exactly what this process looks like: you click a link, the browser thinks for a minute, the URL changes, then your new page loads. The browser manages your ",[228,229,230],"em",{},"intent"," to navigate to the new page in the way of updating the URL that is currently being displayed, then displaying the page.",[120,233,234,235,237,238,241],{},"In an application, the mechanics can differ, but the overall process is remarkably similar. As a user, you tap on a cog wheel icon with the ",[228,236,230],{}," to access settings and the application ",[228,239,240],{},"routes"," you to the settings screen, very much like a Web page would work. In fact, if you will recall, Flutter itself was born out of the Web-world, so many of the concepts and paradigms are still closely related to its history with the Web.",[243,244,246],"h3",{"id":245},"where-flutter-differs-from-the-web","Where Flutter differs from the Web",[120,248,249],{},"Where Flutter differs from the Web, however, is in how it manages the state objects of screens not currently in the foreground.",[171,251,252,266],{},[174,253,256,263],{"icon":254,"title":255},"i-lucide-globe","On the Web",[120,257,258,259,262],{},"Once you navigate away from a page, you ",[111,260,261],{},"lose the state"," of the elements on the page (unless the state has been written to a local cache, then injected back into the page when you navigate back to it, or the backend manages the state similarly).",[120,264,265],{},"This is the reason why your Web browser will ask you if you are quite certain that you would like to navigate away from a form once you have started to fill it out but have not yet submitted it: if you do, the state of the form will be lost, and you will have to start over if you navigate back to the page.",[174,267,270,271,274],{"icon":268,"title":269},"i-lucide-layers","In Flutter","Flutter can ",[111,272,273],{},"retain state"," for screens not currently being displayed to the user, but from which they had previously navigated.",[276,277,278,279,282],"tip",{},"The best way to visualize this is to consider a ",[111,280,281],{},"deck of playing cards",". When navigating around the Web, only a single playing card can be on the table at a time. When navigating within Flutter, however, cards are added and removed from the stack of cards on the table.",[243,284,286],{"id":285},"the-navigation-stack","The navigation stack",[120,288,289,290,293],{},"It is this concept of a navigation ",[228,291,292],{},"stack"," that will help us to make sense of how routing works in applications:",[295,296,298,303,306,310,313,317,320,324],"steps",{"level":297},"4",[299,300,302],"h4",{"id":301},"the-app-launches","The app launches",[120,304,305],{},"When an application launches, the first card in the stack is a loading screen.",[299,307,309],{"id":308},"the-main-screen-replaces-the-loading-screen","The main screen replaces the loading screen",[120,311,312],{},"Once the application has loaded, the loading screen card is removed from the stack and replaced with the main application card.",[299,314,316],{"id":315},"a-new-screen-is-pushed","A new screen is pushed",[120,318,319],{},"When a user performs an action that routes them to a new screen, a card is placed on top of the main application card, thereby creating a stack of two cards. Since the main screen card has not been removed from the stack, its associated state is maintained, along with the state of the new card on the stack.",[299,321,323],{"id":322},"the-back-button-pops-it","The back button pops it",[120,325,326,327,330],{},"When the user presses the back button, the new card is removed from the stack, returning us to the original card in the stack — the main screen — where it has maintained its own state while it was ",[228,328,329],{},"under"," the new screen.",[132,332,333,334,337,338,341,342,344,345,348],{},"This whole navigating and routing process of stacking cards happens inside the scope of a ",[139,335,336],{},"Navigator",", which we will discuss in the next section. What is important to note is that an application can have ",[111,339,340],{},"multiple"," ",[139,343,336],{},"s, thereby creating ",[228,346,347],{},"nested"," navigation stacks.",[120,350,351],{},"Let us dive into Navigator 1.0 and learn how all this works.",[166,353,355],{"id":354},"introduction-to-navigator-10","Introduction to Navigator 1.0",[120,357,358,359,361,362,365],{},"Flutter has both imperative and declarative routing mechanisms, using ",[139,360,336],{}," and ",[139,363,364],{},"Router",", respectively.",[132,367,368,369,371,372,374,375,377,378,381,382,384,385,387,388,390,391,393],{},"Before we break down what that means, it is important to note that ",[139,370,336],{}," is sometimes referred to as ",[228,373,125],{}," whereas the Router API is sometimes referred to as ",[228,376,129],{},". This does ",[111,379,380],{},"not"," mean that ",[139,383,364],{}," replaces ",[139,386,336],{}," — far from it (this may contrast with how one might typically consider version numbers to work, with newer versions replacing older ones). In fact, ",[139,389,364],{},", as we will discuss later, is built using ",[139,392,336],{},".",[120,395,396,397,399,400,361,402,404],{},"We need to understand how Navigator works before we can understand ",[139,398,364],{},", so let us dig into the concept, starting with the difference between imperative and declarative code, as understanding this concept is vital to understanding how ",[139,401,336],{},[139,403,364],{}," work.",[243,406,408],{"id":407},"imperative-vs-declarative","Imperative vs. declarative",[171,410,411,423],{},[174,412,415,416,419,420,422],{"icon":413,"title":414},"i-lucide-list-ordered","Imperative — Navigator","Code that is ",[228,417,418],{},"imperative"," has step-by-step instructions to complete the task at hand. ",[139,421,336],{}," (the imperative system) is given a list of routes, then told to navigate to one of those routes.",[174,424,427,430,431,434,435,437,438,440,441,444,445,447],{"icon":425,"title":426},"i-lucide-scroll-text","Declarative — Router",[228,428,429],{},"Declarative"," code simply provides a description of what you ",[228,432,433],{},"want"," but not necessarily how to go about getting it. ",[139,436,364],{}," requires a bit more boilerplate code to describe how to parse the intent of a route (by, for example, pulling out arguments passed along with the route) before performing the routing action. By using ",[139,439,364],{},", we are simply describing where we want to navigate ",[228,442,443],{},"to"," and with what properties; then ",[139,446,364],{}," figures out how to make that happen for us.",[120,449,450,451,453,454,341,457,459],{},"These are not mutually exclusive, however. In fact, ",[139,452,364],{}," (the declarative system) is built ",[228,455,456],{},"using",[139,458,336],{}," (the imperative system).",[243,461,463],{"id":462},"pushing-and-popping-a-route","Pushing and popping a route",[120,465,466,467,469,470,473],{},"Let us explore using ",[139,468,336],{}," to route to a new screen and back. The first thing we will need is two screens to route between. One of those screens can be the main screen of your application. The other screen should have its own ",[139,471,472],{},"Scaffold"," and body. Feel free to use this as a starting point:",[475,476,481],"pre",{"className":477,"code":478,"filename":479,"language":480,"meta":106,"style":106},"language-dart shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","class MainScreen extends StatelessWidget {\n  const MainScreen({super.key});\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      appBar: AppBar(\n        title: const Text('This is the main screen of my application'),\n      ),\n      body: Center(\n        child: ElevatedButton(\n          child: const Text('Navigate!'),\n          onPressed: () {\n            \u002F\u002F Navigate to new screen when tapped.\n          },\n        ),\n      ),\n    );\n  }\n}\n\nclass SecondScreen extends StatelessWidget {\n  const SecondScreen({super.key});\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      appBar: AppBar(\n        title: const Text(\"I'm so glad you found your way over. \"),\n      ),\n      body: Center(\n        child: ElevatedButton(\n          onPressed: () {\n            \u002F\u002F Navigate back to main screen when tapped.\n          },\n          child: const Text('See you later!'),\n        ),\n      ),\n    );\n  }\n}\n","Example 8.1 · Example 8.1.dart","dart",[139,482,483,491,497,504,510,516,522,528,534,540,546,552,558,564,570,576,582,587,593,599,605,610,616,622,627,632,637,642,647,653,658,663,668,673,679,684,690,695,700,705,710],{"__ignoreMap":106},[484,485,488],"span",{"class":486,"line":487},"line",1,[484,489,490],{},"class MainScreen extends StatelessWidget {\n",[484,492,494],{"class":486,"line":493},2,[484,495,496],{},"  const MainScreen({super.key});\n",[484,498,500],{"class":486,"line":499},3,[484,501,503],{"emptyLinePlaceholder":502},true,"\n",[484,505,507],{"class":486,"line":506},4,[484,508,509],{},"  @override\n",[484,511,513],{"class":486,"line":512},5,[484,514,515],{},"  Widget build(BuildContext context) {\n",[484,517,519],{"class":486,"line":518},6,[484,520,521],{},"    return Scaffold(\n",[484,523,525],{"class":486,"line":524},7,[484,526,527],{},"      appBar: AppBar(\n",[484,529,531],{"class":486,"line":530},8,[484,532,533],{},"        title: const Text('This is the main screen of my application'),\n",[484,535,537],{"class":486,"line":536},9,[484,538,539],{},"      ),\n",[484,541,543],{"class":486,"line":542},10,[484,544,545],{},"      body: Center(\n",[484,547,549],{"class":486,"line":548},11,[484,550,551],{},"        child: ElevatedButton(\n",[484,553,555],{"class":486,"line":554},12,[484,556,557],{},"          child: const Text('Navigate!'),\n",[484,559,561],{"class":486,"line":560},13,[484,562,563],{},"          onPressed: () {\n",[484,565,567],{"class":486,"line":566},14,[484,568,569],{},"            \u002F\u002F Navigate to new screen when tapped.\n",[484,571,573],{"class":486,"line":572},15,[484,574,575],{},"          },\n",[484,577,579],{"class":486,"line":578},16,[484,580,581],{},"        ),\n",[484,583,585],{"class":486,"line":584},17,[484,586,539],{},[484,588,590],{"class":486,"line":589},18,[484,591,592],{},"    );\n",[484,594,596],{"class":486,"line":595},19,[484,597,598],{},"  }\n",[484,600,602],{"class":486,"line":601},20,[484,603,604],{},"}\n",[484,606,608],{"class":486,"line":607},21,[484,609,503],{"emptyLinePlaceholder":502},[484,611,613],{"class":486,"line":612},22,[484,614,615],{},"class SecondScreen extends StatelessWidget {\n",[484,617,619],{"class":486,"line":618},23,[484,620,621],{},"  const SecondScreen({super.key});\n",[484,623,625],{"class":486,"line":624},24,[484,626,503],{"emptyLinePlaceholder":502},[484,628,630],{"class":486,"line":629},25,[484,631,509],{},[484,633,635],{"class":486,"line":634},26,[484,636,515],{},[484,638,640],{"class":486,"line":639},27,[484,641,521],{},[484,643,645],{"class":486,"line":644},28,[484,646,527],{},[484,648,650],{"class":486,"line":649},29,[484,651,652],{},"        title: const Text(\"I'm so glad you found your way over. \"),\n",[484,654,656],{"class":486,"line":655},30,[484,657,539],{},[484,659,661],{"class":486,"line":660},31,[484,662,545],{},[484,664,666],{"class":486,"line":665},32,[484,667,551],{},[484,669,671],{"class":486,"line":670},33,[484,672,563],{},[484,674,676],{"class":486,"line":675},34,[484,677,678],{},"            \u002F\u002F Navigate back to main screen when tapped.\n",[484,680,682],{"class":486,"line":681},35,[484,683,575],{},[484,685,687],{"class":486,"line":686},36,[484,688,689],{},"          child: const Text('See you later!'),\n",[484,691,693],{"class":486,"line":692},37,[484,694,581],{},[484,696,698],{"class":486,"line":697},38,[484,699,539],{},[484,701,703],{"class":486,"line":702},39,[484,704,592],{},[484,706,708],{"class":486,"line":707},40,[484,709,598],{},[484,711,713],{"class":486,"line":712},41,[484,714,604],{},[120,716,717,718,720,721,724,725,727,728,731,732,734],{},"Now all that is left is to set up ",[139,719,336],{}," to route from the first screen to the second, then back. On the first screen, set the ",[139,722,723],{},"onPressed"," method to ask ",[139,726,336],{}," to ",[111,729,730],{},"push"," a new ",[228,733,174],{}," onto the stack:",[475,736,739],{"className":477,"code":737,"filename":738,"language":480,"meta":106,"style":106},"onPressed: () {\n  Navigator.push(\n    context,\n    MaterialPageRoute(builder: (context) => const SecondScreen()),\n  );\n}\n","Example 8.2 · Example 8.2.dart",[139,740,741,746,751,756,761,766],{"__ignoreMap":106},[484,742,743],{"class":486,"line":487},[484,744,745],{},"onPressed: () {\n",[484,747,748],{"class":486,"line":493},[484,749,750],{},"  Navigator.push(\n",[484,752,753],{"class":486,"line":499},[484,754,755],{},"    context,\n",[484,757,758],{"class":486,"line":506},[484,759,760],{},"    MaterialPageRoute(builder: (context) => const SecondScreen()),\n",[484,762,763],{"class":486,"line":512},[484,764,765],{},"  );\n",[484,767,768],{"class":486,"line":518},[484,769,604],{},[120,771,772,773,724,775,727,777,780],{},"Tapping the button now will route you to the second screen. Getting back to the first screen is just as easy. On the second screen, set the ",[139,774,723],{},[139,776,336],{},[111,778,779],{},"pop"," the current card off the stack:",[475,782,785],{"className":477,"code":783,"filename":784,"language":480,"meta":106,"style":106},"onPressed: () {\n  Navigator.pop(context);\n}\n","Example 8.3 · Example 8.3.dart",[139,786,787,791,796],{"__ignoreMap":106},[484,788,789],{"class":486,"line":487},[484,790,745],{},[484,792,793],{"class":486,"line":493},[484,794,795],{},"  Navigator.pop(context);\n",[484,797,798],{"class":486,"line":499},[484,799,604],{},[120,801,802,341,805],{},[228,803,804],{},"Runnable copy:",[139,806,807],{},"examples\u002Fflutter_for_jobseekers_ch08\u002Flib\u002Fnavigator_1\u002Fpush_pop.dart",[120,809,810],{},"And… that is it! You now know all there is to know about navigating to a new screen and back! Except…",[812,813,814],"warning",{},[179,815,816,823,834],{},[182,817,818,819,822],{},"What if you want to navigate to the ",[111,820,821],{},"same screen from multiple places"," in your application? Would that not mean writing a bunch of duplicate code?",[182,824,825,826,829,830,833],{},"What if you want to ",[111,827,828],{},"replace"," the current screen with the new one so a user cannot press the ",[139,831,832],{},"back"," button to get back to a screen they should not, like when the splash screen is finished, and the user is presented with the main screen?",[182,835,825,836,839],{},[111,837,838],{},"pass information"," from the first screen to the second? This method will not work at all since no data can be passed into the route.",[120,841,842],{},"We have a bit more to investigate, so let us investigate each of these use cases one at a time.",[166,844,190],{"id":845},"routing-using-named-routes",[120,847,848,849,851,852,855,856,859,860,863,864,867,868,871,872,393],{},"Let us suppose that your application has a settings screen, which you want to be easily accessible from any screen. On each new screen you create, you add a button to navigate to the settings screen, but the ",[139,850,723],{}," method always has a ",[139,853,854],{},"Navigator.push"," to a ",[139,857,858],{},"MaterialPageRoute"," with a ",[139,861,862],{},"builder"," method. That is a lot of code just to navigate to a new screen! Plus, it means that we must remember exactly what our settings screen's widget name is (and what happens if you have a similarly named widget somewhere else in the application? Oh boy!) Would it not be great if we could simply route to the new screen ",[228,865,866],{},"by name","? Like, ",[228,869,870],{},"hey, Navigator! Send me to the settings screen!"," Fortunately, we can: by using ",[111,873,874],{},"named routes",[132,876,877,899],{},[120,878,879,880,882,883,886,887,890,891,894,895,898],{},"Named routes will look familiar to anyone who has used a Web browser before. Each route will look like a path in a URL. In fact, ",[139,881,336],{}," will treat these named routes ",[228,884,885],{},"like"," a URL path. The difference will be that there will not be any ",[139,888,889],{},"www"," or ",[139,892,893],{},".com"," associated with the routes since that is all handled internally. Instead, we are worried about what would come ",[228,896,897],{},"after"," that.",[120,900,901,902,906,907,909,910,914,915,918,919,922,923,926],{},"It is like going to ",[148,903,904],{"href":904,"rel":905},"https:\u002F\u002Fwww.my-favorite-website.com\u002Fmy-favorite-page",[152]," except that ",[139,908,336],{}," knows about the ",[148,911,912],{"href":912,"rel":913},"https:\u002F\u002Fwww.my-favorite-website.com",[152]," part, so we do not have to specify it. That leaves us with just the ",[139,916,917],{},"\u002Fmy-favorite-page"," to manage. If you went to the ",[139,920,921],{},"main"," website, there would not be anything after the slash, so the slash itself is the ",[139,924,925],{},"root"," of the route. This will make more sense as we dig into some examples.",[243,928,930],{"id":929},"setting-up-the-routing-table","Setting up the routing table",[120,932,933,934,937,938,940,941,944],{},"To set up named routes, you will have to find your main ",[139,935,936],{},"MaterialApp"," and define a couple of properties. The first thing we will need to define is the ",[139,939,240],{}," parameter, which contains a ",[139,942,943],{},"map"," of route names to the screen we are navigating to:",[475,946,949],{"className":477,"code":947,"filename":948,"language":480,"meta":106,"style":106},"MaterialApp(\n  routes: {\n    '\u002F': (context) => const MainScreen(),\n    '\u002Fsettings': (context) => const SettingsScreen(),\n  },\n)\n","Example 8.4 · Example 8.4.dart",[139,950,951,956,961,966,971,976],{"__ignoreMap":106},[484,952,953],{"class":486,"line":487},[484,954,955],{},"MaterialApp(\n",[484,957,958],{"class":486,"line":493},[484,959,960],{},"  routes: {\n",[484,962,963],{"class":486,"line":499},[484,964,965],{},"    '\u002F': (context) => const MainScreen(),\n",[484,967,968],{"class":486,"line":506},[484,969,970],{},"    '\u002Fsettings': (context) => const SettingsScreen(),\n",[484,972,973],{"class":486,"line":512},[484,974,975],{},"  },\n",[484,977,978],{"class":486,"line":518},[484,979,980],{},")\n",[120,982,983,984,987,988,991,992,994],{},"The next thing we need to do is set an initial route, which will display the main content of the application when it is loaded. Before, we used to do this by specifying the ",[139,985,986],{},"home"," property. Now, we will use the ",[139,989,990],{},"initialRoute"," property — so go ahead and remove ",[139,993,986],{},"!",[475,996,999],{"className":477,"code":997,"filename":998,"language":480,"meta":106,"style":106},"MaterialApp(\n  initialRoute: '\u002F',\n  routes: {\n    '\u002F': (context) => const MainScreen(),\n    '\u002Fsettings': (context) => const SettingsScreen(),\n  },\n)\n","Example 8.5 · Example 8.5.dart",[139,1000,1001,1005,1010,1014,1018,1022,1026],{"__ignoreMap":106},[484,1002,1003],{"class":486,"line":487},[484,1004,955],{},[484,1006,1007],{"class":486,"line":493},[484,1008,1009],{},"  initialRoute: '\u002F',\n",[484,1011,1012],{"class":486,"line":499},[484,1013,960],{},[484,1015,1016],{"class":486,"line":506},[484,1017,965],{},[484,1019,1020],{"class":486,"line":512},[484,1021,970],{},[484,1023,1024],{"class":486,"line":518},[484,1025,975],{},[484,1027,1028],{"class":486,"line":524},[484,1029,980],{},[243,1031,1033],{"id":1032},"navigating-to-and-replacing-a-named-route","Navigating to and replacing a named route",[120,1035,1036,1037,1040,1041,1044,1045,1047],{},"At this point, we have everything we need to solve our first ",[228,1038,1039],{},"two"," problems: we can now navigate to a ",[228,1042,1043],{},"named"," route, and we can ",[228,1046,828],{}," a route with a new one. Let us do that.",[120,1049,1050,1051,1053,1054,1057,1058,1060],{},"First, to navigate to a named route, we replace ",[139,1052,854],{}," with ",[139,1055,1056],{},"Navigator.pushNamed",", and instead of passing in a ",[139,1059,858],{},", we pass in the name of the route:",[475,1062,1065],{"className":477,"code":1063,"filename":1064,"language":480,"meta":106,"style":106},"onPressed: () {\n  Navigator.pushNamed('\u002Fsettings');\n}\n","Example 8.6 · Example 8.6.dart",[139,1066,1067,1071,1076],{"__ignoreMap":106},[484,1068,1069],{"class":486,"line":487},[484,1070,745],{},[484,1072,1073],{"class":486,"line":493},[484,1074,1075],{},"  Navigator.pushNamed('\u002Fsettings');\n",[484,1077,1078],{"class":486,"line":499},[484,1079,604],{},[120,1081,1082,1083,1086],{},"If you want to replace the current card in the stack with your new route, you use ",[139,1084,1085],{},"Navigator.pushReplacementNamed",", instead:",[475,1088,1091],{"className":477,"code":1089,"filename":1090,"language":480,"meta":106,"style":106},"onPressed: () {\n  Navigator.pushReplacementNamed('\u002Fsettings');\n}\n","Example 8.7 · Example 8.7.dart",[139,1092,1093,1097,1102],{"__ignoreMap":106},[484,1094,1095],{"class":486,"line":487},[484,1096,745],{},[484,1098,1099],{"class":486,"line":493},[484,1100,1101],{},"  Navigator.pushReplacementNamed('\u002Fsettings');\n",[484,1103,1104],{"class":486,"line":499},[484,1105,604],{},[132,1107,1108,1111,1112,1115,1116,361,1118,1121,1122,1125,1126,361,1129,1132],{},[111,1109,1110],{},"Corrected:"," both calls are missing the ",[139,1113,1114],{},"BuildContext",", so they do not compile. Like ",[139,1117,854],{},[139,1119,1120],{},"Navigator.pop",", the static methods take ",[139,1123,1124],{},"context"," as their first argument: ",[139,1127,1128],{},"Navigator.pushNamed(context, '\u002Fsettings')",[139,1130,1131],{},"Navigator.pushReplacementNamed(context, '\u002Fsettings')",", as the runnable copy does.",[120,1134,1135,1136,1139,1140,1142],{},"Of course, there is also a ",[139,1137,1138],{},"Navigator.pushReplacement"," for when you are not using named routes and navigating back whether using named routes or a ",[139,1141,858],{}," works just the same.",[243,1144,1146],{"id":1145},"storing-the-route-name-on-the-screen","Storing the route name on the screen",[120,1148,1149,1150,1153],{},"You also have the option of specifying the route name in the destination widget. Outside of the ",[139,1151,1152],{},"build()"," method, try adding something like the following:",[475,1155,1158],{"className":477,"code":1156,"filename":1157,"language":480,"meta":106,"style":106},"static const routeName = '\u002Fsettings';\n","Example 8.8 · Example 8.8.dart",[139,1159,1160],{"__ignoreMap":106},[484,1161,1162],{"class":486,"line":487},[484,1163,1156],{},[120,1165,1166],{},"Then you can use it in your routing table:",[475,1168,1170],{"className":477,"code":1169,"filename":1157,"language":480,"meta":106,"style":106},"routes: {\n  '\u002F': (context) => const Home(),\n  SettingsScreen.routeName: (context) => const SettingsScreen(),\n},\n",[139,1171,1172,1177,1182,1187],{"__ignoreMap":106},[484,1173,1174],{"class":486,"line":487},[484,1175,1176],{},"routes: {\n",[484,1178,1179],{"class":486,"line":493},[484,1180,1181],{},"  '\u002F': (context) => const Home(),\n",[484,1183,1184],{"class":486,"line":499},[484,1185,1186],{},"  SettingsScreen.routeName: (context) => const SettingsScreen(),\n",[484,1188,1189],{"class":486,"line":506},[484,1190,1191],{},"},\n",[120,1193,1194,1196,1197,727,1200,1203],{},[228,1195,136],{}," Example 8.8 routes ",[139,1198,1199],{},"'\u002F'",[139,1201,1202],{},"MainScreen",", as the earlier examples on this page do.",[120,1205,1206,341,1208,1211,1212,1215],{},[228,1207,804],{},[139,1209,1210],{},"examples\u002Fflutter_for_jobseekers_ch08\u002Flib\u002Fnavigator_1\u002Fnamed_routes.dart"," (the book does not print ",[139,1213,1214],{},"SettingsScreen","; the example adds a minimal one)",[276,1217,1218,1219,393],{},"Using named routes is an excellent and effortless way to keep the routing in your app clean and simple. If you decide to write a new settings screen but you do not want to immediately remove the old one, it is much easier to update the named route than it is to track down all the different places where you are generating a ",[139,1220,858],{},[132,1222,1223,1225],{},[111,1224,1110],{}," the Flutter team no longer recommends named routes for most apps. \"Although named routes can handle deep links, the behavior is always the same and can't be customized. When a new deep link is received by the platform, Flutter pushes a new Route onto the Navigator regardless of where the user currently is. Flutter also doesn't support the browser forward button for applications using named routes. For these reasons, we don't recommend using named routes in most applications. Instead, use a routing package like go_router or use Navigator with MaterialPageRoute\" (Flutter, n.d.-a).",[166,1227,193],{"id":1228},"passing-arguments-into-a-route",[120,1230,1231,1232,1235],{},"Sometimes it is necessary to pass some data back and forth when routing. For example, you may find yourself with a product page where the user can choose the quantity of an item to purchase, then immediately checkout their order. The checkout screen would need to know what the desired product is, the quantity, and the price. Passing in this data using arguments means you can build a more generic checkout screen, capable of accepting ",[228,1233,1234],{},"any"," item(s), in any quantity, at any price.",[120,1237,1238],{},"There are a couple of separate ways we can do this:",[171,1240,1241,1248],{},[174,1242,1244,1245,393],{"icon":51,"title":1243},"Arguments read by the widget","Defining the arguments and passing them into the widget, which extracts them with ",[139,1246,1247],{},"ModalRoute.of(context)",[174,1249,1252,1253,1255],{"icon":1250,"title":1251},"i-lucide-factory","onGenerateRoute","Extracting the arguments using ",[139,1254,1251],{}," and handing them to the screen.",[120,1257,1258],{},"Let us first look at the former method.",[243,1260,1262],{"id":1261},"defining-an-arguments-class","Defining an arguments class",[120,1264,1265],{},"To begin, we need to define a class that contains the arguments that we will pass into our route. Let us build one for the shopping cart example, making sure that it is flexible enough to accept multiple items when we go to checkout:",[475,1267,1270],{"className":477,"code":1268,"filename":1269,"language":480,"meta":106,"style":106},"class StoreItem {\n  final String name;\n  final double price;\n\n  const StoreItem({required this.name, required this.price});\n}\n\nclass CheckoutScreenArguments {\n  final List\u003CMap\u003CStoreItem, int>> shoppingCart;\n\n  const CheckoutScreenArguments(this.shoppingCart);\n}\n","Example 8.9 · Example 8.9.dart",[139,1271,1272,1277,1282,1287,1291,1296,1300,1304,1309,1314,1318,1323],{"__ignoreMap":106},[484,1273,1274],{"class":486,"line":487},[484,1275,1276],{},"class StoreItem {\n",[484,1278,1279],{"class":486,"line":493},[484,1280,1281],{},"  final String name;\n",[484,1283,1284],{"class":486,"line":499},[484,1285,1286],{},"  final double price;\n",[484,1288,1289],{"class":486,"line":506},[484,1290,503],{"emptyLinePlaceholder":502},[484,1292,1293],{"class":486,"line":512},[484,1294,1295],{},"  const StoreItem({required this.name, required this.price});\n",[484,1297,1298],{"class":486,"line":518},[484,1299,604],{},[484,1301,1302],{"class":486,"line":524},[484,1303,503],{"emptyLinePlaceholder":502},[484,1305,1306],{"class":486,"line":530},[484,1307,1308],{},"class CheckoutScreenArguments {\n",[484,1310,1311],{"class":486,"line":536},[484,1312,1313],{},"  final List\u003CMap\u003CStoreItem, int>> shoppingCart;\n",[484,1315,1316],{"class":486,"line":542},[484,1317,503],{"emptyLinePlaceholder":502},[484,1319,1320],{"class":486,"line":548},[484,1321,1322],{},"  const CheckoutScreenArguments(this.shoppingCart);\n",[484,1324,1325],{"class":486,"line":554},[484,1326,604],{},[120,1328,1329,1330,1333,1334,1337,1338,1341,1342,1345,1346,1348],{},"Here, we have created a ",[139,1331,1332],{},"StoreItem"," class, which will hold both the name of the item and its price. Next, we made a ",[139,1335,1336],{},"CheckoutScreenArguments"," class with one property (although we could have as many properties as we want.) This property will accept a ",[139,1339,1340],{},"List"," of ",[139,1343,1344],{},"Map","s that map a ",[139,1347,1332],{}," to the quantity of items in the cart. That might look like the following:",[475,1350,1353],{"className":477,"code":1351,"filename":1352,"language":480,"meta":106,"style":106},"const StoreItem shirt = StoreItem(name: \"Super Rad Shirt\", price: 12.99);\nconst StoreItem shoes = StoreItem(name: \"Comfy Shoes\", price: 34.99);\n\nconst CheckoutScreenArguments shoppingCart = CheckoutScreenArguments(\n  [\n    {shirt: 4},\n    {shoes: 1},\n  ],\n);\n","Example 8.10 · Example 8.10.dart",[139,1354,1355,1360,1365,1369,1374,1379,1384,1389,1394],{"__ignoreMap":106},[484,1356,1357],{"class":486,"line":487},[484,1358,1359],{},"const StoreItem shirt = StoreItem(name: \"Super Rad Shirt\", price: 12.99);\n",[484,1361,1362],{"class":486,"line":493},[484,1363,1364],{},"const StoreItem shoes = StoreItem(name: \"Comfy Shoes\", price: 34.99);\n",[484,1366,1367],{"class":486,"line":499},[484,1368,503],{"emptyLinePlaceholder":502},[484,1370,1371],{"class":486,"line":506},[484,1372,1373],{},"const CheckoutScreenArguments shoppingCart = CheckoutScreenArguments(\n",[484,1375,1376],{"class":486,"line":512},[484,1377,1378],{},"  [\n",[484,1380,1381],{"class":486,"line":518},[484,1382,1383],{},"    {shirt: 4},\n",[484,1385,1386],{"class":486,"line":524},[484,1387,1388],{},"    {shoes: 1},\n",[484,1390,1391],{"class":486,"line":530},[484,1392,1393],{},"  ],\n",[484,1395,1396],{"class":486,"line":536},[484,1397,1398],{},");\n",[120,1400,1401,341,1403,1406],{},[228,1402,804],{},[139,1404,1405],{},"examples\u002Fflutter_for_jobseekers_ch08\u002Flib\u002Fnavigator_1\u002Fstore.dart",". The book's text lost the integer part of the prices in conversion; they are restored from the publisher's companion repository, Example 8.10 (BPB Publications, n.d.).",[243,1408,1410,1411],{"id":1409},"reading-the-arguments-with-modalrouteof","Reading the arguments with ",[139,1412,1413],{},"ModalRoute.of",[120,1415,1416,1417,1420,1421,1423,1424,1427],{},"Now that we have a proper screen arguments class, we need to make a couple of changes to the screen that takes the arguments. First, we will move the route name into the screen, itself (",[111,1418,1419],{},"Line 2",", in the following example), then we can extract the arguments using the ",[139,1422,1247],{}," inherited widget (",[111,1425,1426],{},"Lines 8 and 9","):",[475,1429,1432],{"className":477,"code":1430,"filename":1431,"language":480,"meta":106,"style":106},"class CheckoutScreen extends StatelessWidget {\n  static const routeName = '\u002Fcheckout';\n\n  const CheckoutScreen({Key? key}) : super(key: key);\n\n  @override\n  Widget build(BuildContext context) {\n    final args =\n        ModalRoute.of(context)!.settings.arguments as CheckoutScreenArguments;\n\n    return Scaffold(\n      body: ListView.builder(\n        itemCount: args.shoppingCart.length,\n        itemBuilder: ((context, index) => ListTile(\n              title: Text(args.shoppingCart[index].keys.first.name),\n              subtitle: Text(\n                  '${args.shoppingCart[index].values.first} × ${args.shoppingCart[index].keys.first.price}'),\n            )),\n      ),\n    );\n  }\n}\n","Example 8.11 · Example 8.11.dart",[139,1433,1434,1439,1444,1448,1453,1457,1461,1465,1470,1475,1479,1483,1488,1493,1498,1503,1508,1513,1518,1522,1526,1530],{"__ignoreMap":106},[484,1435,1436],{"class":486,"line":487},[484,1437,1438],{},"class CheckoutScreen extends StatelessWidget {\n",[484,1440,1441],{"class":486,"line":493},[484,1442,1443],{},"  static const routeName = '\u002Fcheckout';\n",[484,1445,1446],{"class":486,"line":499},[484,1447,503],{"emptyLinePlaceholder":502},[484,1449,1450],{"class":486,"line":506},[484,1451,1452],{},"  const CheckoutScreen({Key? key}) : super(key: key);\n",[484,1454,1455],{"class":486,"line":512},[484,1456,503],{"emptyLinePlaceholder":502},[484,1458,1459],{"class":486,"line":518},[484,1460,509],{},[484,1462,1463],{"class":486,"line":524},[484,1464,515],{},[484,1466,1467],{"class":486,"line":530},[484,1468,1469],{},"    final args =\n",[484,1471,1472],{"class":486,"line":536},[484,1473,1474],{},"        ModalRoute.of(context)!.settings.arguments as CheckoutScreenArguments;\n",[484,1476,1477],{"class":486,"line":542},[484,1478,503],{"emptyLinePlaceholder":502},[484,1480,1481],{"class":486,"line":548},[484,1482,521],{},[484,1484,1485],{"class":486,"line":554},[484,1486,1487],{},"      body: ListView.builder(\n",[484,1489,1490],{"class":486,"line":560},[484,1491,1492],{},"        itemCount: args.shoppingCart.length,\n",[484,1494,1495],{"class":486,"line":566},[484,1496,1497],{},"        itemBuilder: ((context, index) => ListTile(\n",[484,1499,1500],{"class":486,"line":572},[484,1501,1502],{},"              title: Text(args.shoppingCart[index].keys.first.name),\n",[484,1504,1505],{"class":486,"line":578},[484,1506,1507],{},"              subtitle: Text(\n",[484,1509,1510],{"class":486,"line":584},[484,1511,1512],{},"                  '${args.shoppingCart[index].values.first} × ${args.shoppingCart[index].keys.first.price}'),\n",[484,1514,1515],{"class":486,"line":589},[484,1516,1517],{},"            )),\n",[484,1519,1520],{"class":486,"line":595},[484,1521,539],{},[484,1523,1524],{"class":486,"line":601},[484,1525,592],{},[484,1527,1528],{"class":486,"line":607},[484,1529,598],{},[484,1531,1532],{"class":486,"line":612},[484,1533,604],{},[120,1535,1536],{},"Now that you have a variable holding the screen arguments, all that is left is to pass your shopping cart over to the checkout screen:",[475,1538,1541],{"className":477,"code":1539,"filename":1540,"language":480,"meta":106,"style":106},"ElevatedButton(\n  child: const Text('Checkout'),\n  onPressed: () {\n    Navigator.pushNamed(\n      context,\n      CheckoutScreen.routeName,\n      arguments: shoppingCart,\n    );\n  },\n),\n","Example 8.12 · Example 8.12.dart",[139,1542,1543,1548,1553,1558,1563,1568,1573,1578,1582,1586],{"__ignoreMap":106},[484,1544,1545],{"class":486,"line":487},[484,1546,1547],{},"ElevatedButton(\n",[484,1549,1550],{"class":486,"line":493},[484,1551,1552],{},"  child: const Text('Checkout'),\n",[484,1554,1555],{"class":486,"line":499},[484,1556,1557],{},"  onPressed: () {\n",[484,1559,1560],{"class":486,"line":506},[484,1561,1562],{},"    Navigator.pushNamed(\n",[484,1564,1565],{"class":486,"line":512},[484,1566,1567],{},"      context,\n",[484,1569,1570],{"class":486,"line":518},[484,1571,1572],{},"      CheckoutScreen.routeName,\n",[484,1574,1575],{"class":486,"line":524},[484,1576,1577],{},"      arguments: shoppingCart,\n",[484,1579,1580],{"class":486,"line":530},[484,1581,592],{},[484,1583,1584],{"class":486,"line":536},[484,1585,975],{},[484,1587,1588],{"class":486,"line":542},[484,1589,1590],{},"),\n",[120,1592,1593,341,1595,1598,1599,1602,1603,1606],{},[228,1594,804],{},[139,1596,1597],{},"examples\u002Fflutter_for_jobseekers_ch08\u002Flib\u002Fnavigator_1\u002Froute_arguments.dart"," (adds a ",[139,1600,1601],{},"ProductScreen"," that holds the ",[111,1604,1605],{},"Checkout"," button)",[243,1608,1610,1611],{"id":1609},"using-ongenerateroute","Using ",[139,1612,1251],{},[120,1614,1615,1616,1618,1619,1621,1622,1624],{},"That is all it takes to pass arguments into a route! There is another way we can do it, though. The second method uses the ",[139,1617,1251],{}," parameter in your ",[139,1620,936],{},". Using this method, you do not need to extract the arguments inside the widget using ",[139,1623,1247],{},":",[475,1626,1629],{"className":477,"code":1627,"filename":1628,"language":480,"meta":106,"style":106},"MaterialApp(\n  onGenerateRoute: (settings) {\n    if (settings.name == MessageScreen.routeName) {\n      final args = settings.arguments as MessageScreenArguments;\n\n      return MaterialPageRoute(\n        builder: (context) {\n          return MessageScreen(\n            title: args.title,\n            message: args.message,\n          );\n        },\n      );\n    }\n\n    if (settings.name == CheckoutScreen.routeName) {\n      final args = settings.arguments as CheckoutScreenArguments;\n\n      return MaterialPageRoute(\n        builder: (context) {\n          return CheckoutScreen(\n            shoppingCart: args.shoppingCart,\n          );\n        },\n      );\n    }\n\n    assert(false, 'Need to implement ${settings.name}');\n    return null;\n  },\n)\n","Example 8.13 · Example 8.13.dart",[139,1630,1631,1635,1640,1645,1650,1654,1659,1664,1669,1674,1679,1684,1689,1694,1699,1703,1708,1713,1717,1721,1725,1730,1735,1739,1743,1747,1751,1755,1760,1765,1769],{"__ignoreMap":106},[484,1632,1633],{"class":486,"line":487},[484,1634,955],{},[484,1636,1637],{"class":486,"line":493},[484,1638,1639],{},"  onGenerateRoute: (settings) {\n",[484,1641,1642],{"class":486,"line":499},[484,1643,1644],{},"    if (settings.name == MessageScreen.routeName) {\n",[484,1646,1647],{"class":486,"line":506},[484,1648,1649],{},"      final args = settings.arguments as MessageScreenArguments;\n",[484,1651,1652],{"class":486,"line":512},[484,1653,503],{"emptyLinePlaceholder":502},[484,1655,1656],{"class":486,"line":518},[484,1657,1658],{},"      return MaterialPageRoute(\n",[484,1660,1661],{"class":486,"line":524},[484,1662,1663],{},"        builder: (context) {\n",[484,1665,1666],{"class":486,"line":530},[484,1667,1668],{},"          return MessageScreen(\n",[484,1670,1671],{"class":486,"line":536},[484,1672,1673],{},"            title: args.title,\n",[484,1675,1676],{"class":486,"line":542},[484,1677,1678],{},"            message: args.message,\n",[484,1680,1681],{"class":486,"line":548},[484,1682,1683],{},"          );\n",[484,1685,1686],{"class":486,"line":554},[484,1687,1688],{},"        },\n",[484,1690,1691],{"class":486,"line":560},[484,1692,1693],{},"      );\n",[484,1695,1696],{"class":486,"line":566},[484,1697,1698],{},"    }\n",[484,1700,1701],{"class":486,"line":572},[484,1702,503],{"emptyLinePlaceholder":502},[484,1704,1705],{"class":486,"line":578},[484,1706,1707],{},"    if (settings.name == CheckoutScreen.routeName) {\n",[484,1709,1710],{"class":486,"line":584},[484,1711,1712],{},"      final args = settings.arguments as CheckoutScreenArguments;\n",[484,1714,1715],{"class":486,"line":589},[484,1716,503],{"emptyLinePlaceholder":502},[484,1718,1719],{"class":486,"line":595},[484,1720,1658],{},[484,1722,1723],{"class":486,"line":601},[484,1724,1663],{},[484,1726,1727],{"class":486,"line":607},[484,1728,1729],{},"          return CheckoutScreen(\n",[484,1731,1732],{"class":486,"line":612},[484,1733,1734],{},"            shoppingCart: args.shoppingCart,\n",[484,1736,1737],{"class":486,"line":618},[484,1738,1683],{},[484,1740,1741],{"class":486,"line":624},[484,1742,1688],{},[484,1744,1745],{"class":486,"line":629},[484,1746,1693],{},[484,1748,1749],{"class":486,"line":634},[484,1750,1698],{},[484,1752,1753],{"class":486,"line":639},[484,1754,503],{"emptyLinePlaceholder":502},[484,1756,1757],{"class":486,"line":644},[484,1758,1759],{},"    assert(false, 'Need to implement ${settings.name}');\n",[484,1761,1762],{"class":486,"line":649},[484,1763,1764],{},"    return null;\n",[484,1766,1767],{"class":486,"line":655},[484,1768,975],{},[484,1770,1771],{"class":486,"line":660},[484,1772,980],{},[120,1774,1775,1776,1779,1780,1783,1784,1779,1787,1789],{},"In this example, we are building a ",[139,1777,1778],{},"MessageScreen"," using a ",[139,1781,1782],{},"MessageScreenArguments"," class, as well as our trusty ",[139,1785,1786],{},"CheckoutScreen",[139,1788,1336],{}," class.",[132,1791,1792,1794,1795,1797,1798,1801,1802,1805,1806,1808,1809,1811,1812,361,1815,1818,1819,1822,1823,361,1825,1827],{},[111,1793,1110],{}," the ",[139,1796,1786],{}," above has no ",[139,1799,1800],{},"shoppingCart"," parameter; its only constructor parameter is ",[139,1803,1804],{},"key",", because it reads the cart from ",[139,1807,1247],{},". For ",[139,1810,1251],{},", the screen takes the cart through its constructor (",[139,1813,1814],{},"final List\u003CMap\u003CStoreItem, int>> shoppingCart;",[139,1816,1817],{},"required this.shoppingCart",") and reads that field instead of ",[139,1820,1821],{},"args",". The book does not print ",[139,1824,1778],{},[139,1826,1782],{},"; the runnable copy defines both.",[812,1829,1830,1831,1836],{},"While this reduces the complexity of the individual screens you are routing to, it ",[111,1832,1833,1834],{},"increases the complexity of your ",[139,1835,936],{},". For this reason, it is common to break out the method into its own file, which would look something like in the following example:",[475,1838,1841],{"className":477,"code":1839,"filename":1840,"language":480,"meta":106,"style":106},"MaterialApp(\n  onGenerateRoute: routeHandler,\n);\n\u002F\u002F The following method can be saved to a different file, then imported.\nMaterialPageRoute? routeHandler(settings) {\n  (settings) {\n    if (settings.name == MessageScreen.routeName) {\n      final args = settings.arguments as MessageScreenArguments;\n\n      return MaterialPageRoute(\n        builder: (context) {\n          return MessageScreen(\n            title: args.title,\n            message: args.message,\n          );\n        },\n      );\n    }\n\n    assert(false, 'Route handler not configured for ${settings.name}');\n    return null;\n  };\n}\n","Example 8.14 · Example 8.14.dart",[139,1842,1843,1847,1852,1856,1861,1866,1871,1875,1879,1883,1887,1891,1895,1899,1903,1907,1911,1915,1919,1923,1928,1932,1937],{"__ignoreMap":106},[484,1844,1845],{"class":486,"line":487},[484,1846,955],{},[484,1848,1849],{"class":486,"line":493},[484,1850,1851],{},"  onGenerateRoute: routeHandler,\n",[484,1853,1854],{"class":486,"line":499},[484,1855,1398],{},[484,1857,1858],{"class":486,"line":506},[484,1859,1860],{},"\u002F\u002F The following method can be saved to a different file, then imported.\n",[484,1862,1863],{"class":486,"line":512},[484,1864,1865],{},"MaterialPageRoute? routeHandler(settings) {\n",[484,1867,1868],{"class":486,"line":518},[484,1869,1870],{},"  (settings) {\n",[484,1872,1873],{"class":486,"line":524},[484,1874,1644],{},[484,1876,1877],{"class":486,"line":530},[484,1878,1649],{},[484,1880,1881],{"class":486,"line":536},[484,1882,503],{"emptyLinePlaceholder":502},[484,1884,1885],{"class":486,"line":542},[484,1886,1658],{},[484,1888,1889],{"class":486,"line":548},[484,1890,1663],{},[484,1892,1893],{"class":486,"line":554},[484,1894,1668],{},[484,1896,1897],{"class":486,"line":560},[484,1898,1673],{},[484,1900,1901],{"class":486,"line":566},[484,1902,1678],{},[484,1904,1905],{"class":486,"line":572},[484,1906,1683],{},[484,1908,1909],{"class":486,"line":578},[484,1910,1688],{},[484,1912,1913],{"class":486,"line":584},[484,1914,1693],{},[484,1916,1917],{"class":486,"line":589},[484,1918,1698],{},[484,1920,1921],{"class":486,"line":595},[484,1922,503],{"emptyLinePlaceholder":502},[484,1924,1925],{"class":486,"line":601},[484,1926,1927],{},"    assert(false, 'Route handler not configured for ${settings.name}');\n",[484,1929,1930],{"class":486,"line":607},[484,1931,1764],{},[484,1933,1934],{"class":486,"line":612},[484,1935,1936],{},"  };\n",[484,1938,1939],{"class":486,"line":618},[484,1940,604],{},[132,1942,1943,1945,1946,1949,1950,1953,1954,1957,1958,1960,1961,1964,1965,1132],{},[111,1944,1110],{}," this ",[139,1947,1948],{},"routeHandler"," never routes anywhere. Its body is a single closure expression, ",[139,1951,1952],{},"(settings) { ... };",", which is created and thrown away without being called, so the function falls off its end and always returns ",[139,1955,1956],{},"null",", and ",[139,1959,1251],{}," fails for every route name. The ",[139,1962,1963],{},"if"," statements belong directly in the function body, with a typed parameter: ",[139,1966,1967],{},"MaterialPageRoute? routeHandler(RouteSettings settings) { if (...) ... }",[120,1969,1970,341,1972,1975,1976,1978,1979,1981,1982,1985],{},[228,1971,804],{},[139,1973,1974],{},"examples\u002Fflutter_for_jobseekers_ch08\u002Flib\u002Fnavigator_1\u002Fon_generate_route.dart"," (with ",[139,1977,1778],{},", ",[139,1980,1782],{}," and a ",[139,1983,1984],{},"HomeScreen"," to start from)",[120,1987,1988,1989,1991],{},"Ultimately, Flutter gives you the flexibility to build your application in a way that makes the most sense for whatever project you are working on. Using ",[139,1990,1251],{}," in this way may be overkill, especially if only one or two of your screens require arguments. That will be up to you to decide.",[276,1993,1994,1995,1997,1998,2001],{},"Can you think of another thing that you can use ",[139,1996,1251],{}," for? (Here is a hint for one thing you could use it for: ",[111,1999,2000],{},"analytics",".)",[166,2003,196],{"id":2004},"returning-data-from-a-screen",[120,2006,2007],{},"Passing data to a new screen is extremely useful, but sometimes we want to pass data back to the screen we were just looking at. You are building an input that asks your user to choose between two options. The design of the option picker is such that it would be clearer to the user by being on its own screen, rather than inline on the form. The user taps on a widget which routes them to a new screen where they make their selection, and then they are routed back to the initial screen where their option is used to update the form. The question becomes: how do we accomplish passing the data back to the initial screen after they have made their selection?",[276,2009,2010,2011,2017,2018,2022],{},"The solution is much simpler than one might imagine. When routing to a new screen, you can simply ",[111,2012,2013,2016],{},[139,2014,2015],{},"await"," the result"," and pass the data back in the ",[111,2019,2020],{},[139,2021,1120],{}," method.",[243,2024,2026],{"id":2025},"the-two-screens","The two screens",[120,2028,2029,2030,2033],{},"Let us start by building a simple screen where we will both display the result of the selection and a button that we will use to route to the selection screen. We know this will need to be a ",[139,2031,2032],{},"StatefulWidget"," because we need to update the widgets based on the return value:",[475,2035,2038],{"className":477,"code":2036,"filename":2037,"language":480,"meta":106,"style":106},"class _HomeState extends State\u003CHome> {\n  String? _chosenOption;\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      body: Column(\n        children: [\n          Text(_chosenOption ?? ''),\n          ElevatedButton(\n            child: const Text('Choose one'),\n            onPressed: () {\n              \u002F\u002F TODO: Route to the option screen and get the value back\n            },\n          ),\n        ],\n      ),\n    );\n  }\n}\n","Example 8.15 · Example 8.15.dart",[139,2039,2040,2045,2050,2054,2058,2062,2067,2072,2077,2082,2087,2092,2097,2102,2107,2112,2116,2120,2124],{"__ignoreMap":106},[484,2041,2042],{"class":486,"line":487},[484,2043,2044],{},"class _HomeState extends State\u003CHome> {\n",[484,2046,2047],{"class":486,"line":493},[484,2048,2049],{},"  String? _chosenOption;\n",[484,2051,2052],{"class":486,"line":499},[484,2053,509],{},[484,2055,2056],{"class":486,"line":506},[484,2057,515],{},[484,2059,2060],{"class":486,"line":512},[484,2061,521],{},[484,2063,2064],{"class":486,"line":518},[484,2065,2066],{},"      body: Column(\n",[484,2068,2069],{"class":486,"line":524},[484,2070,2071],{},"        children: [\n",[484,2073,2074],{"class":486,"line":530},[484,2075,2076],{},"          Text(_chosenOption ?? ''),\n",[484,2078,2079],{"class":486,"line":536},[484,2080,2081],{},"          ElevatedButton(\n",[484,2083,2084],{"class":486,"line":542},[484,2085,2086],{},"            child: const Text('Choose one'),\n",[484,2088,2089],{"class":486,"line":548},[484,2090,2091],{},"            onPressed: () {\n",[484,2093,2094],{"class":486,"line":554},[484,2095,2096],{},"              \u002F\u002F TODO: Route to the option screen and get the value back\n",[484,2098,2099],{"class":486,"line":560},[484,2100,2101],{},"            },\n",[484,2103,2104],{"class":486,"line":566},[484,2105,2106],{},"          ),\n",[484,2108,2109],{"class":486,"line":572},[484,2110,2111],{},"        ],\n",[484,2113,2114],{"class":486,"line":578},[484,2115,539],{},[484,2117,2118],{"class":486,"line":584},[484,2119,592],{},[484,2121,2122],{"class":486,"line":589},[484,2123,598],{},[484,2125,2126],{"class":486,"line":595},[484,2127,604],{},[120,2129,2130,2131,2134,2135,2138],{},"Since ",[139,2132,2133],{},"_chosenOption"," is nullable, the ",[139,2136,2137],{},"Text"," will display nothing, for now. Next, we need a screen to route to, which includes our options:",[475,2140,2143],{"className":477,"code":2141,"filename":2142,"language":480,"meta":106,"style":106},"class ChooseOneScreen extends StatelessWidget {\n  const ChooseOneScreen({super.key});\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      body: Column(\n        children: [\n          ElevatedButton(\n            child: const Text('Option One'),\n            onPressed: () {\n              \u002F\u002F TODO: Return “Option One”\n            },\n          ),\n          ElevatedButton(\n            child: const Text('Option Two'),\n            onPressed: () {\n              \u002F\u002F TODO: Return “Option Two”\n            },\n          ),\n        ],\n      ),\n    );\n  }\n}\n","Example 8.16 · Example 8.16.dart",[139,2144,2145,2150,2155,2159,2163,2167,2171,2175,2179,2183,2188,2192,2197,2201,2205,2209,2214,2218,2223,2227,2231,2235,2239,2243,2247],{"__ignoreMap":106},[484,2146,2147],{"class":486,"line":487},[484,2148,2149],{},"class ChooseOneScreen extends StatelessWidget {\n",[484,2151,2152],{"class":486,"line":493},[484,2153,2154],{},"  const ChooseOneScreen({super.key});\n",[484,2156,2157],{"class":486,"line":499},[484,2158,503],{"emptyLinePlaceholder":502},[484,2160,2161],{"class":486,"line":506},[484,2162,509],{},[484,2164,2165],{"class":486,"line":512},[484,2166,515],{},[484,2168,2169],{"class":486,"line":518},[484,2170,521],{},[484,2172,2173],{"class":486,"line":524},[484,2174,2066],{},[484,2176,2177],{"class":486,"line":530},[484,2178,2071],{},[484,2180,2181],{"class":486,"line":536},[484,2182,2081],{},[484,2184,2185],{"class":486,"line":542},[484,2186,2187],{},"            child: const Text('Option One'),\n",[484,2189,2190],{"class":486,"line":548},[484,2191,2091],{},[484,2193,2194],{"class":486,"line":554},[484,2195,2196],{},"              \u002F\u002F TODO: Return “Option One”\n",[484,2198,2199],{"class":486,"line":560},[484,2200,2101],{},[484,2202,2203],{"class":486,"line":566},[484,2204,2106],{},[484,2206,2207],{"class":486,"line":572},[484,2208,2081],{},[484,2210,2211],{"class":486,"line":578},[484,2212,2213],{},"            child: const Text('Option Two'),\n",[484,2215,2216],{"class":486,"line":584},[484,2217,2091],{},[484,2219,2220],{"class":486,"line":589},[484,2221,2222],{},"              \u002F\u002F TODO: Return “Option Two”\n",[484,2224,2225],{"class":486,"line":595},[484,2226,2101],{},[484,2228,2229],{"class":486,"line":601},[484,2230,2106],{},[484,2232,2233],{"class":486,"line":607},[484,2234,2111],{},[484,2236,2237],{"class":486,"line":612},[484,2238,539],{},[484,2240,2241],{"class":486,"line":618},[484,2242,592],{},[484,2244,2245],{"class":486,"line":624},[484,2246,598],{},[484,2248,2249],{"class":486,"line":629},[484,2250,604],{},[243,2252,2254],{"id":2253},"popping-with-a-value","Popping with a value",[120,2256,2257,2258,2260,2261,2264,2265,2268],{},"Now that we have all the boilerplate code in place, we need to write the ",[139,2259,723],{}," methods. Let us look at the buttons on the ",[139,2262,2263],{},"ChooseOneScreen"," first. For those, we will need to pop the current route off the stack, then return the value to the initial screen. Previously we used ",[139,2266,2267],{},"Navigator.pop(context)"," to route back to the previous screen without returning a value. We will do the same thing here, the only difference will be that we are adding another argument to the method, being the value that we would like to return.",[120,2270,2271,2272,2274],{},"Update each of the ",[139,2273,723],{}," methods to pop the route with an appropriate return value. In this case, we know that we expect a String to be returned, so let us return exactly that. Here is an example for the first button:",[475,2276,2279],{"className":477,"code":2277,"filename":2278,"language":480,"meta":106,"style":106},"onPressed: () {\n  Navigator.pop(context, 'Option One');\n},\n","Example 8.17 · Example 8.17.dart",[139,2280,2281,2285,2290],{"__ignoreMap":106},[484,2282,2283],{"class":486,"line":487},[484,2284,745],{},[484,2286,2287],{"class":486,"line":493},[484,2288,2289],{},"  Navigator.pop(context, 'Option One');\n",[484,2291,2292],{"class":486,"line":499},[484,2293,1191],{},[243,2295,2297],{"id":2296},"awaiting-the-result","Awaiting the result",[120,2299,2300,2301,2303],{},"Next, we need to route to the screen from the initial one and wait for the value to be returned. Back on the initial screen, let us start by creating an ",[139,2302,723],{}," method that navigates to our new screen:",[475,2305,2308],{"className":477,"code":2306,"filename":2307,"language":480,"meta":106,"style":106},"onPressed: () {\n  Navigator.push(\n    context,\n    MaterialPageRoute(\n      builder: (context) => const ChooseOneScreen(),\n    ),\n  );\n},\n","Example 8.18 · Example 8.18.dart",[139,2309,2310,2314,2318,2322,2327,2332,2337,2341],{"__ignoreMap":106},[484,2311,2312],{"class":486,"line":487},[484,2313,745],{},[484,2315,2316],{"class":486,"line":493},[484,2317,750],{},[484,2319,2320],{"class":486,"line":499},[484,2321,755],{},[484,2323,2324],{"class":486,"line":506},[484,2325,2326],{},"    MaterialPageRoute(\n",[484,2328,2329],{"class":486,"line":512},[484,2330,2331],{},"      builder: (context) => const ChooseOneScreen(),\n",[484,2333,2334],{"class":486,"line":518},[484,2335,2336],{},"    ),\n",[484,2338,2339],{"class":486,"line":524},[484,2340,765],{},[484,2342,2343],{"class":486,"line":530},[484,2344,1191],{},[120,2346,2347,2348,2350,2351,2353,2354,2357,2358,1794,2360,2362],{},"This will let us route to the screen, but it lacks a way to receive data when we pop the route. As mentioned before, we want to ",[139,2349,2015],{}," the result and the first step of that is turning our ",[139,2352,723],{}," method into an ",[139,2355,2356],{},"async"," method. Then, we can ",[139,2359,2015],{},[139,2361,336],{}," call:",[475,2364,2367],{"className":477,"code":2365,"filename":2366,"language":480,"meta":106,"style":106},"onPressed: () async {\n  await Navigator.push(\n    context,\n    MaterialPageRoute(\n      builder: (context) => const ChooseOneScreen(),\n    ),\n  );\n},\n","Example 8.19 · Example 8.19.dart",[139,2368,2369,2374,2379,2383,2387,2391,2395,2399],{"__ignoreMap":106},[484,2370,2371],{"class":486,"line":487},[484,2372,2373],{},"onPressed: () async {\n",[484,2375,2376],{"class":486,"line":493},[484,2377,2378],{},"  await Navigator.push(\n",[484,2380,2381],{"class":486,"line":499},[484,2382,755],{},[484,2384,2385],{"class":486,"line":506},[484,2386,2326],{},[484,2388,2389],{"class":486,"line":512},[484,2390,2331],{},[484,2392,2393],{"class":486,"line":518},[484,2394,2336],{},[484,2396,2397],{"class":486,"line":524},[484,2398,765],{},[484,2400,2401],{"class":486,"line":530},[484,2402,1191],{},[120,2404,2405,2406,2408],{},"Finally, by assigning the result of the ",[139,2407,336],{}," call to a variable, we can successfully retrieve the data which was returned from the popped route:",[475,2410,2413],{"className":477,"code":2411,"filename":2412,"language":480,"meta":106,"style":106},"onPressed: () async {\n  String? _chosenOption = await Navigator.push(\n    context,\n    MaterialPageRoute(\n      builder: (context) => const ChooseOneScreen(),\n    ),\n  );\n  print('The chosen option is $_chosenOption');\n},\n","Example 8.20 · Example 8.20.dart",[139,2414,2415,2419,2424,2428,2432,2436,2440,2444,2449],{"__ignoreMap":106},[484,2416,2417],{"class":486,"line":487},[484,2418,2373],{},[484,2420,2421],{"class":486,"line":493},[484,2422,2423],{},"  String? _chosenOption = await Navigator.push(\n",[484,2425,2426],{"class":486,"line":499},[484,2427,755],{},[484,2429,2430],{"class":486,"line":506},[484,2431,2326],{},[484,2433,2434],{"class":486,"line":512},[484,2435,2331],{},[484,2437,2438],{"class":486,"line":518},[484,2439,2336],{},[484,2441,2442],{"class":486,"line":524},[484,2443,765],{},[484,2445,2446],{"class":486,"line":530},[484,2447,2448],{},"  print('The chosen option is $_chosenOption');\n",[484,2450,2451],{"class":486,"line":536},[484,2452,1191],{},[120,2454,2455,2457,2458,2461,2462,2465,2466,2469,2470,2473],{},[228,2456,136],{}," Example 8.20 logs the result with ",[139,2459,2460],{},"log"," from ",[139,2463,2464],{},"dart:developer"," instead of ",[139,2467,2468],{},"print",", and calls ",[139,2471,2472],{},"setState(() {})"," after it.",[120,2475,2476,2477,2480],{},"If this is combined with a stateful widget and ",[139,2478,2479],{},"setState",", you could capture the value and display it on the screen. Alternatively, you could capture the returned value and pass it into a method to parse and perform an action upon. Truly, the options are limitless.",[120,2482,2483,341,2485,2488,2489,2491,2492,2494],{},[228,2484,804],{},[139,2486,2487],{},"examples\u002Fflutter_for_jobseekers_ch08\u002Flib\u002Fnavigator_1\u002Freturn_data.dart"," (stores the result with ",[139,2490,2479],{},", so the ",[139,2493,2137],{}," shows the chosen option)",[166,2496,199],{"id":2497},"animating-a-widget-from-one-route-to-another",[120,2499,2500],{},"There is an enormous difference between creating a fully functioning application and an application that is well-polished.",[171,2502,2503,2508],{},[174,2504,2507],{"icon":2505,"title":2506},"i-lucide-check","Fully functioning","Assumes you have met the bare minimum in terms of the app meeting the functional goals.",[174,2509,2512,2513,2516],{"icon":2510,"title":2511},"i-lucide-sparkles","Well-polished","Implies that you have taken the time to think about the look and feel of the application. A well-polished application does not just include a well-coordinated color scheme and widgets that look and feel like they belong together and support each other. A well-polished application uses ",[111,2514,2515],{},"animations"," to unify the experience for the user.",[120,2518,2519,2520,890,2522,2524],{},"Animations are an integral design element that serves to smooth out state transitions and focus a user's attention on the right place at the right time. They can be subtle or grand but serve the same purpose. When you ",[139,2521,730],{},[139,2523,779],{}," a route, Flutter creates a subtle animation to indicate that you have changed screens. Still, the content from one screen to the next, although it may be related, appears to disappear from one and re-appear on the other.",[120,2526,2527],{},"Let us build a couple of screens to play with:",[475,2529,2532],{"className":477,"code":2530,"filename":2531,"language":480,"meta":106,"style":106},"class Home extends StatelessWidget {\n  const Home({super.key});\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      body: Column(\n        children: [\n          const Icon(Icons.flutter_dash),\n          ElevatedButton(\n            child: const Text('Say \"hi\" to Dash!'),\n            onPressed: () {\n              Navigator.push(\n                context,\n                MaterialPageRoute(\n                  builder: (context) => const HelloDash(),\n                ),\n              );\n            },\n          ),\n        ],\n      ),\n    );\n  }\n}\n\nclass HelloDash extends StatelessWidget {\n  const HelloDash({super.key});\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      body: Center(\n        child: Column(\n          mainAxisAlignment: MainAxisAlignment.center,\n          children: [\n            const Icon(\n              Icons.flutter_dash,\n              color: Colors.blue,\n              size: 128,\n            ),\n            const Text('Hi Dash!'),\n            ElevatedButton(\n              child: const Text('Back'),\n              onPressed: () {\n                Navigator.pop(context);\n              },\n            ),\n          ],\n        ),\n      ),\n    );\n  }\n}\n","Example 8.21 · Example 8.21.dart",[139,2533,2534,2539,2544,2548,2552,2556,2560,2564,2568,2573,2577,2582,2586,2591,2596,2601,2606,2611,2616,2620,2624,2628,2632,2636,2640,2644,2648,2653,2658,2662,2666,2670,2674,2678,2683,2688,2693,2698,2703,2708,2713,2718,2724,2730,2736,2742,2748,2754,2759,2765,2770,2775,2780,2785],{"__ignoreMap":106},[484,2535,2536],{"class":486,"line":487},[484,2537,2538],{},"class Home extends StatelessWidget {\n",[484,2540,2541],{"class":486,"line":493},[484,2542,2543],{},"  const Home({super.key});\n",[484,2545,2546],{"class":486,"line":499},[484,2547,503],{"emptyLinePlaceholder":502},[484,2549,2550],{"class":486,"line":506},[484,2551,509],{},[484,2553,2554],{"class":486,"line":512},[484,2555,515],{},[484,2557,2558],{"class":486,"line":518},[484,2559,521],{},[484,2561,2562],{"class":486,"line":524},[484,2563,2066],{},[484,2565,2566],{"class":486,"line":530},[484,2567,2071],{},[484,2569,2570],{"class":486,"line":536},[484,2571,2572],{},"          const Icon(Icons.flutter_dash),\n",[484,2574,2575],{"class":486,"line":542},[484,2576,2081],{},[484,2578,2579],{"class":486,"line":548},[484,2580,2581],{},"            child: const Text('Say \"hi\" to Dash!'),\n",[484,2583,2584],{"class":486,"line":554},[484,2585,2091],{},[484,2587,2588],{"class":486,"line":560},[484,2589,2590],{},"              Navigator.push(\n",[484,2592,2593],{"class":486,"line":566},[484,2594,2595],{},"                context,\n",[484,2597,2598],{"class":486,"line":572},[484,2599,2600],{},"                MaterialPageRoute(\n",[484,2602,2603],{"class":486,"line":578},[484,2604,2605],{},"                  builder: (context) => const HelloDash(),\n",[484,2607,2608],{"class":486,"line":584},[484,2609,2610],{},"                ),\n",[484,2612,2613],{"class":486,"line":589},[484,2614,2615],{},"              );\n",[484,2617,2618],{"class":486,"line":595},[484,2619,2101],{},[484,2621,2622],{"class":486,"line":601},[484,2623,2106],{},[484,2625,2626],{"class":486,"line":607},[484,2627,2111],{},[484,2629,2630],{"class":486,"line":612},[484,2631,539],{},[484,2633,2634],{"class":486,"line":618},[484,2635,592],{},[484,2637,2638],{"class":486,"line":624},[484,2639,598],{},[484,2641,2642],{"class":486,"line":629},[484,2643,604],{},[484,2645,2646],{"class":486,"line":634},[484,2647,503],{"emptyLinePlaceholder":502},[484,2649,2650],{"class":486,"line":639},[484,2651,2652],{},"class HelloDash extends StatelessWidget {\n",[484,2654,2655],{"class":486,"line":644},[484,2656,2657],{},"  const HelloDash({super.key});\n",[484,2659,2660],{"class":486,"line":649},[484,2661,503],{"emptyLinePlaceholder":502},[484,2663,2664],{"class":486,"line":655},[484,2665,509],{},[484,2667,2668],{"class":486,"line":660},[484,2669,515],{},[484,2671,2672],{"class":486,"line":665},[484,2673,521],{},[484,2675,2676],{"class":486,"line":670},[484,2677,545],{},[484,2679,2680],{"class":486,"line":675},[484,2681,2682],{},"        child: Column(\n",[484,2684,2685],{"class":486,"line":681},[484,2686,2687],{},"          mainAxisAlignment: MainAxisAlignment.center,\n",[484,2689,2690],{"class":486,"line":686},[484,2691,2692],{},"          children: [\n",[484,2694,2695],{"class":486,"line":692},[484,2696,2697],{},"            const Icon(\n",[484,2699,2700],{"class":486,"line":697},[484,2701,2702],{},"              Icons.flutter_dash,\n",[484,2704,2705],{"class":486,"line":702},[484,2706,2707],{},"              color: Colors.blue,\n",[484,2709,2710],{"class":486,"line":707},[484,2711,2712],{},"              size: 128,\n",[484,2714,2715],{"class":486,"line":712},[484,2716,2717],{},"            ),\n",[484,2719,2721],{"class":486,"line":2720},42,[484,2722,2723],{},"            const Text('Hi Dash!'),\n",[484,2725,2727],{"class":486,"line":2726},43,[484,2728,2729],{},"            ElevatedButton(\n",[484,2731,2733],{"class":486,"line":2732},44,[484,2734,2735],{},"              child: const Text('Back'),\n",[484,2737,2739],{"class":486,"line":2738},45,[484,2740,2741],{},"              onPressed: () {\n",[484,2743,2745],{"class":486,"line":2744},46,[484,2746,2747],{},"                Navigator.pop(context);\n",[484,2749,2751],{"class":486,"line":2750},47,[484,2752,2753],{},"              },\n",[484,2755,2757],{"class":486,"line":2756},48,[484,2758,2717],{},[484,2760,2762],{"class":486,"line":2761},49,[484,2763,2764],{},"          ],\n",[484,2766,2768],{"class":486,"line":2767},50,[484,2769,581],{},[484,2771,2773],{"class":486,"line":2772},51,[484,2774,539],{},[484,2776,2778],{"class":486,"line":2777},52,[484,2779,592],{},[484,2781,2783],{"class":486,"line":2782},53,[484,2784,598],{},[484,2786,2788],{"class":486,"line":2787},54,[484,2789,604],{},[120,2791,2792,2793,2796],{},"In this example, we have an icon of Dash with a button that routes to a new screen. The new screen has a larger, more colorful version of the same icon. There is a subtle animation when the route transitions, but otherwise, Dash appears to teleport from one place to another. How do we know this is the ",[228,2794,2795],{},"same"," Dash that was on the previous screen?",[120,2798,2799,2800,2803,2804,2807,2808,2811,2812,2815],{},"Let us fix this by making Dash ",[228,2801,2802],{},"fly","! Wrap the ",[139,2805,2806],{},"Icon"," widget on both screens with a ",[139,2809,2810],{},"Hero"," widget and give them both a ",[139,2813,2814],{},"tag"," property with the same value:",[475,2817,2820],{"className":477,"code":2818,"filename":2819,"language":480,"meta":106,"style":106},"const Hero(\n  tag: 'dash',\n  child: ...,\n),\n","Example 8.22 · Example 8.22.dart",[139,2821,2822,2827,2832,2837],{"__ignoreMap":106},[484,2823,2824],{"class":486,"line":487},[484,2825,2826],{},"const Hero(\n",[484,2828,2829],{"class":486,"line":493},[484,2830,2831],{},"  tag: 'dash',\n",[484,2833,2834],{"class":486,"line":499},[484,2835,2836],{},"  child: ...,\n",[484,2838,2839],{"class":486,"line":506},[484,2840,1590],{},[120,2842,2843,341,2845],{},[228,2844,804],{},[139,2846,2847],{},"examples\u002Fflutter_for_jobseekers_ch08\u002Flib\u002Fnavigator_1\u002Fhero_animation.dart",[120,2849,2850,2851,2853],{},"Now, tapping the button makes Dash ",[228,2852,2802],{}," from one screen to the next!",[276,2855,2856,2857,2859],{},"Choosing one or two elements to transition between routes as a ",[139,2858,2810],{}," will help the user keep track of how elements on the two screens relate, adding polish to the finished product.",[120,2861,2862,2863,2865,2866,2869,2870,2874],{},"The ",[139,2864,2810],{}," widget is one of ",[228,2867,2868],{},"many"," widgets which can be used to animate elements in Flutter. Although animating widgets in Flutter is not covered in this book, there are loads of excellent resources online which cover many aspects of animating widgets, including creating your own animations. Check the ",[148,2871,2873],{"href":2872},"#further-reading","Further reading"," section at the end of this chapter for a link to the documentation.",[166,2876,202],{"id":2877},"introduction-to-navigator-20-the-router-api",[120,2879,2880],{},"What Navigator 1.0 lacks in ability, it makes up for with simplicity. Unfortunately, the simplicity of Navigator 1.0 can be quite limiting at times. It is not hard to imagine a scenario wherein one would want to:",[171,2882,2883,2888,2897],{},[174,2884,2887],{"icon":2885,"title":2886},"i-lucide-clapperboard","Custom transitions","Implement a custom screen transition animation.",[174,2889,2892,2893,2896],{"icon":2890,"title":2891},"i-lucide-link","Deep linking","Route within the application based on a URI, such as ",[139,2894,2895],{},"\u002Fcontact\u002F0"," telling the application to show us the first contact.",[174,2898,2901,2902,2904],{"icon":2899,"title":2900},"i-lucide-network","Nested routing","Use ",[228,2903,347],{}," routing.",[120,2906,2907],{},"More elaborate applications are usually better served by Navigator 2.0.",[132,2909,2910,2911,393],{},"When Navigator 2.0 was first introduced, it was named as such. This is still the name by which many people know it and refer to it as. However, the more appropriate name that has since been adopted by the Flutter team is the ",[111,2912,2913],{},"Router API",[120,2915,2916,2917,1427],{},"The Router API is not a breaking change. Rather, it adds a new set of APIs for us to leverage and build more complex applications with far more freedom. With that freedom, however, comes a lot more complexity. Let us first start by looking at a diagram of how the Router API works (",[228,2918,2919],{},"Figure 8.1",[120,2921,2922],{},[2923,2924],"img",{"alt":2925,"src":2926},"Figure 8.1: A flow-chart of the functionality of the Router API. Source: https:\u002F\u002Fmedium.com\u002Fflutter\u002Flearning-flutters-new-navigation-and-routing-system-7c9068155ade","\u002Fimages\u002Fflutter-for-jobseekers\u002Ffigure-8-1.png",[2928,2929,2930],"blockquote",{},[120,2931,2932,2933],{},"Figure 8.1: A flow-chart of the functionality of the Router API. Source: ",[148,2934,2935],{"href":2935,"rel":2936},"https:\u002F\u002Fmedium.com\u002Fflutter\u002Flearning-flutters-new-navigation-and-routing-system-7c9068155ade",[152],[243,2938,2940],{"id":2939},"what-we-will-build","What we will build",[120,2942,2943],{},"We are going to be implementing each of these blocks to create a complete Router API-enabled application. Using our earlier examples, we are going to create a simple application that lists several contacts and routes to a contact details screen when we tap on one.",[171,2945,2946,2950,2955,2960],{},[174,2947,2949],{"icon":254,"title":2948},"Flutter Web","We will target Flutter Web, just so we can observe the URI changing (although in true Flutter form, the application works anywhere.)",[174,2951,2954],{"icon":2952,"title":2953},"i-lucide-undo-2","Back button handling","We will implement back button handling, so we can use a system back button (for example, Android's back button).",[174,2956,2959],{"icon":2957,"title":2958},"i-lucide-move-right","Custom transition","We will customize the screen transition.",[174,2961,2964],{"icon":2962,"title":2963},"i-lucide-file-question","404 page","We will even add a custom 404 page just in case the user tries to enter an invalid path.",[243,2966,2968],{"id":2967},"the-boilerplate","The boilerplate",[120,2970,2971,2972,2975],{},"To get started, we will need to set up a ",[139,2973,2974],{},"Contact"," class, build the base application screen, create a screen that lists the contacts, a contact details screen, and a 404 screen. Since we haven't set up any routing yet, we will have no way to navigate between these screens, but once we are done, it will be nice to have gotten the boilerplate code out of the way.",[120,2977,2978],{},"Without further ado, here is the boilerplate code for our application:",[475,2980,2983],{"className":477,"code":2981,"filename":2982,"language":480,"meta":106,"style":106},"import 'package:flutter\u002Fmaterial.dart';\n\nvoid main() {\n  runApp(const ContactsApp());\n}\n\nclass ContactsApp extends StatefulWidget {\n  const ContactsApp({super.key});\n\n  @override\n  State\u003CStatefulWidget> createState() => _ContactsAppState();\n}\n\nclass _ContactsAppState extends State\u003CContactsApp> {\n\n  @override\n  Widget build(BuildContext context) {\n    return MaterialApp(\n      title: 'Contacts App',\n      home: Container(),\n    );\n  }\n}\n\nclass Contact {\n  final String name;\n  final String email;\n\n  const Contact({\n    required this.name,\n    required this.email,\n  });\n}\n\nclass ContactsListScreen extends StatelessWidget {\n  final List\u003CContact> contacts;\n  final ValueChanged\u003CContact> onTapped;\n\n  const ContactsListScreen({\n    super.key,\n    required this.contacts,\n    required this.onTapped,\n  });\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      body: ListView(\n        children: [\n          for (final Contact contact in contacts)\n            ListTile(\n              title: Text(contact.name),\n              subtitle: Text(contact.email),\n              onTap: () => onTapped(contact),\n            )\n        ],\n      ),\n    );\n  }\n}\n\nclass ContactDetailsScreen extends StatelessWidget {\n  final Contact contact;\n\n  const ContactDetailsScreen({\n    super.key,\n    required this.contact,\n  });\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      body: SafeArea(\n        child: Padding(\n          padding: const EdgeInsets.all(8.0),\n          child: Column(\n            crossAxisAlignment: CrossAxisAlignment.start,\n            children: [\n              Text(\n                contact.name,\n                style: Theme.of(context).textTheme.headline6,\n              ),\n              Text(\n                contact.email,\n                style: Theme.of(context).textTheme.subtitle1,\n              ),\n            ],\n          ),\n        ),\n      ),\n    );\n  }\n}\n","Example 8.23 · Example 8.23.dart",[139,2984,2985,2990,2994,2999,3004,3008,3012,3017,3022,3026,3030,3035,3039,3043,3048,3052,3056,3060,3065,3070,3075,3079,3083,3087,3091,3096,3100,3105,3109,3114,3119,3124,3129,3133,3137,3142,3147,3152,3156,3161,3166,3171,3176,3180,3184,3188,3192,3196,3201,3205,3210,3215,3220,3225,3230,3236,3241,3246,3251,3256,3261,3266,3272,3278,3283,3289,3294,3300,3305,3310,3315,3320,3325,3331,3337,3343,3349,3355,3361,3367,3373,3379,3385,3390,3396,3402,3407,3413,3418,3423,3428,3433,3438],{"__ignoreMap":106},[484,2986,2987],{"class":486,"line":487},[484,2988,2989],{},"import 'package:flutter\u002Fmaterial.dart';\n",[484,2991,2992],{"class":486,"line":493},[484,2993,503],{"emptyLinePlaceholder":502},[484,2995,2996],{"class":486,"line":499},[484,2997,2998],{},"void main() {\n",[484,3000,3001],{"class":486,"line":506},[484,3002,3003],{},"  runApp(const ContactsApp());\n",[484,3005,3006],{"class":486,"line":512},[484,3007,604],{},[484,3009,3010],{"class":486,"line":518},[484,3011,503],{"emptyLinePlaceholder":502},[484,3013,3014],{"class":486,"line":524},[484,3015,3016],{},"class ContactsApp extends StatefulWidget {\n",[484,3018,3019],{"class":486,"line":530},[484,3020,3021],{},"  const ContactsApp({super.key});\n",[484,3023,3024],{"class":486,"line":536},[484,3025,503],{"emptyLinePlaceholder":502},[484,3027,3028],{"class":486,"line":542},[484,3029,509],{},[484,3031,3032],{"class":486,"line":548},[484,3033,3034],{},"  State\u003CStatefulWidget> createState() => _ContactsAppState();\n",[484,3036,3037],{"class":486,"line":554},[484,3038,604],{},[484,3040,3041],{"class":486,"line":560},[484,3042,503],{"emptyLinePlaceholder":502},[484,3044,3045],{"class":486,"line":566},[484,3046,3047],{},"class _ContactsAppState extends State\u003CContactsApp> {\n",[484,3049,3050],{"class":486,"line":572},[484,3051,503],{"emptyLinePlaceholder":502},[484,3053,3054],{"class":486,"line":578},[484,3055,509],{},[484,3057,3058],{"class":486,"line":584},[484,3059,515],{},[484,3061,3062],{"class":486,"line":589},[484,3063,3064],{},"    return MaterialApp(\n",[484,3066,3067],{"class":486,"line":595},[484,3068,3069],{},"      title: 'Contacts App',\n",[484,3071,3072],{"class":486,"line":601},[484,3073,3074],{},"      home: Container(),\n",[484,3076,3077],{"class":486,"line":607},[484,3078,592],{},[484,3080,3081],{"class":486,"line":612},[484,3082,598],{},[484,3084,3085],{"class":486,"line":618},[484,3086,604],{},[484,3088,3089],{"class":486,"line":624},[484,3090,503],{"emptyLinePlaceholder":502},[484,3092,3093],{"class":486,"line":629},[484,3094,3095],{},"class Contact {\n",[484,3097,3098],{"class":486,"line":634},[484,3099,1281],{},[484,3101,3102],{"class":486,"line":639},[484,3103,3104],{},"  final String email;\n",[484,3106,3107],{"class":486,"line":644},[484,3108,503],{"emptyLinePlaceholder":502},[484,3110,3111],{"class":486,"line":649},[484,3112,3113],{},"  const Contact({\n",[484,3115,3116],{"class":486,"line":655},[484,3117,3118],{},"    required this.name,\n",[484,3120,3121],{"class":486,"line":660},[484,3122,3123],{},"    required this.email,\n",[484,3125,3126],{"class":486,"line":665},[484,3127,3128],{},"  });\n",[484,3130,3131],{"class":486,"line":670},[484,3132,604],{},[484,3134,3135],{"class":486,"line":675},[484,3136,503],{"emptyLinePlaceholder":502},[484,3138,3139],{"class":486,"line":681},[484,3140,3141],{},"class ContactsListScreen extends StatelessWidget {\n",[484,3143,3144],{"class":486,"line":686},[484,3145,3146],{},"  final List\u003CContact> contacts;\n",[484,3148,3149],{"class":486,"line":692},[484,3150,3151],{},"  final ValueChanged\u003CContact> onTapped;\n",[484,3153,3154],{"class":486,"line":697},[484,3155,503],{"emptyLinePlaceholder":502},[484,3157,3158],{"class":486,"line":702},[484,3159,3160],{},"  const ContactsListScreen({\n",[484,3162,3163],{"class":486,"line":707},[484,3164,3165],{},"    super.key,\n",[484,3167,3168],{"class":486,"line":712},[484,3169,3170],{},"    required this.contacts,\n",[484,3172,3173],{"class":486,"line":2720},[484,3174,3175],{},"    required this.onTapped,\n",[484,3177,3178],{"class":486,"line":2726},[484,3179,3128],{},[484,3181,3182],{"class":486,"line":2732},[484,3183,503],{"emptyLinePlaceholder":502},[484,3185,3186],{"class":486,"line":2738},[484,3187,509],{},[484,3189,3190],{"class":486,"line":2744},[484,3191,515],{},[484,3193,3194],{"class":486,"line":2750},[484,3195,521],{},[484,3197,3198],{"class":486,"line":2756},[484,3199,3200],{},"      body: ListView(\n",[484,3202,3203],{"class":486,"line":2761},[484,3204,2071],{},[484,3206,3207],{"class":486,"line":2767},[484,3208,3209],{},"          for (final Contact contact in contacts)\n",[484,3211,3212],{"class":486,"line":2772},[484,3213,3214],{},"            ListTile(\n",[484,3216,3217],{"class":486,"line":2777},[484,3218,3219],{},"              title: Text(contact.name),\n",[484,3221,3222],{"class":486,"line":2782},[484,3223,3224],{},"              subtitle: Text(contact.email),\n",[484,3226,3227],{"class":486,"line":2787},[484,3228,3229],{},"              onTap: () => onTapped(contact),\n",[484,3231,3233],{"class":486,"line":3232},55,[484,3234,3235],{},"            )\n",[484,3237,3239],{"class":486,"line":3238},56,[484,3240,2111],{},[484,3242,3244],{"class":486,"line":3243},57,[484,3245,539],{},[484,3247,3249],{"class":486,"line":3248},58,[484,3250,592],{},[484,3252,3254],{"class":486,"line":3253},59,[484,3255,598],{},[484,3257,3259],{"class":486,"line":3258},60,[484,3260,604],{},[484,3262,3264],{"class":486,"line":3263},61,[484,3265,503],{"emptyLinePlaceholder":502},[484,3267,3269],{"class":486,"line":3268},62,[484,3270,3271],{},"class ContactDetailsScreen extends StatelessWidget {\n",[484,3273,3275],{"class":486,"line":3274},63,[484,3276,3277],{},"  final Contact contact;\n",[484,3279,3281],{"class":486,"line":3280},64,[484,3282,503],{"emptyLinePlaceholder":502},[484,3284,3286],{"class":486,"line":3285},65,[484,3287,3288],{},"  const ContactDetailsScreen({\n",[484,3290,3292],{"class":486,"line":3291},66,[484,3293,3165],{},[484,3295,3297],{"class":486,"line":3296},67,[484,3298,3299],{},"    required this.contact,\n",[484,3301,3303],{"class":486,"line":3302},68,[484,3304,3128],{},[484,3306,3308],{"class":486,"line":3307},69,[484,3309,503],{"emptyLinePlaceholder":502},[484,3311,3313],{"class":486,"line":3312},70,[484,3314,509],{},[484,3316,3318],{"class":486,"line":3317},71,[484,3319,515],{},[484,3321,3323],{"class":486,"line":3322},72,[484,3324,521],{},[484,3326,3328],{"class":486,"line":3327},73,[484,3329,3330],{},"      body: SafeArea(\n",[484,3332,3334],{"class":486,"line":3333},74,[484,3335,3336],{},"        child: Padding(\n",[484,3338,3340],{"class":486,"line":3339},75,[484,3341,3342],{},"          padding: const EdgeInsets.all(8.0),\n",[484,3344,3346],{"class":486,"line":3345},76,[484,3347,3348],{},"          child: Column(\n",[484,3350,3352],{"class":486,"line":3351},77,[484,3353,3354],{},"            crossAxisAlignment: CrossAxisAlignment.start,\n",[484,3356,3358],{"class":486,"line":3357},78,[484,3359,3360],{},"            children: [\n",[484,3362,3364],{"class":486,"line":3363},79,[484,3365,3366],{},"              Text(\n",[484,3368,3370],{"class":486,"line":3369},80,[484,3371,3372],{},"                contact.name,\n",[484,3374,3376],{"class":486,"line":3375},81,[484,3377,3378],{},"                style: Theme.of(context).textTheme.headline6,\n",[484,3380,3382],{"class":486,"line":3381},82,[484,3383,3384],{},"              ),\n",[484,3386,3388],{"class":486,"line":3387},83,[484,3389,3366],{},[484,3391,3393],{"class":486,"line":3392},84,[484,3394,3395],{},"                contact.email,\n",[484,3397,3399],{"class":486,"line":3398},85,[484,3400,3401],{},"                style: Theme.of(context).textTheme.subtitle1,\n",[484,3403,3405],{"class":486,"line":3404},86,[484,3406,3384],{},[484,3408,3410],{"class":486,"line":3409},87,[484,3411,3412],{},"            ],\n",[484,3414,3416],{"class":486,"line":3415},88,[484,3417,2106],{},[484,3419,3421],{"class":486,"line":3420},89,[484,3422,581],{},[484,3424,3426],{"class":486,"line":3425},90,[484,3427,539],{},[484,3429,3431],{"class":486,"line":3430},91,[484,3432,592],{},[484,3434,3436],{"class":486,"line":3435},92,[484,3437,598],{},[484,3439,3441],{"class":486,"line":3440},93,[484,3442,604],{},[132,3444,3445,3471],{},[120,3446,3447,341,3449,361,3452,3455,3456,3459,3460,3463,3464,361,3466,3463,3469,1132],{},[111,3448,1110],{},[139,3450,3451],{},"headline6",[139,3453,3454],{},"subtitle1"," no longer exist, so this code does not compile on current Flutter. The 2018 ",[139,3457,3458],{},"TextTheme"," names were deprecated in favor of the Material 3 names and then removed (flutter\u002Fflutter, n.d.). Use ",[139,3461,3462],{},"titleLarge"," for ",[139,3465,3451],{},[139,3467,3468],{},"titleMedium",[139,3470,3454],{},[120,3472,3473,3475,3476,3479,3480,3483,3484,3487,3488,3491,3492,3495,3496,393],{},[111,3474,1110],{}," the 404 screen announced above is missing from the boilerplate, but the ",[139,3477,3478],{},"RouterDelegate"," below uses it as ",[139,3481,3482],{},"UnknownScreen",". The book prints it only in the Beamer version at the end of the chapter: a ",[139,3485,3486],{},"StatelessWidget"," whose ",[139,3489,3490],{},"build"," returns ",[139,3493,3494],{},"const Scaffold(body: Center(child: Text('Oops.')))",". The runnable copy keeps the shared screens in ",[139,3497,3498],{},"lib\u002Fcontacts.dart",[120,3500,3501,3502,3505,3506,3509],{},"The only thing that might be new in this code is the ",[139,3503,3504],{},"ValueChanged"," widget. When combined with the ",[139,3507,3508],{},"notifyListeners()"," method, we can trigger widget rebuilds when values are changed.",[132,3511,3512,341,3514,3516,3517,3520,3521,3524,3525,3528,3529,3531,3532,3535,3536,3539,3540,393],{},[111,3513,1110],{},[139,3515,3504],{}," is not a widget. It is a typedef for a callback, ",[139,3518,3519],{},"typedef ValueChanged\u003CT> = void Function(T value)",", a \"Signature for callbacks that report that an underlying value has changed\" (Flutter, n.d.-d). ",[139,3522,3523],{},"ContactsListScreen"," calls ",[139,3526,3527],{},"onTapped(contact)","; the rebuild comes from the ",[139,3530,3478],{},", whose ",[139,3533,3534],{},"_handleContactTapped"," (the function passed as ",[139,3537,3538],{},"onTapped",") calls ",[139,3541,3508],{},[243,3543,3545],{"id":3544},"the-pieces-of-the-router-api","The pieces of the Router API",[120,3547,3548,3549,1981,3551,3554],{},"Now that we have our boilerplate code in place, we can start thinking about the different pieces that make up the Router API. At a minimum, we will need a ",[139,3550,3478],{},[139,3552,3553],{},"RouteInformationParser",", but what are these?",[3556,3557,3558,3574,3590,3608,3629],"field-group",{},[3559,3560,3561,3562,3564,3565,3567,3568,3571,3572,393],"field",{"name":3478},"Defines the behavior of how the application's ",[139,3563,364],{}," learns about and responds to changes in the routing state. It receives the initial route intents and maintains the routing state, then uses this information to build the ",[139,3566,336],{}," with the current list of ",[139,3569,3570],{},"Page","s in the navigation stack. It is the object that sets up the current configuration of the ",[139,3573,364],{},[3559,3575,3576,3577,3579,3580,3582,3583,3586,3587,2022],{"name":3570},"Used to set the ",[139,3578,336],{},"'s history stack. ",[139,3581,3570],{}," objects return a ",[139,3584,3585],{},"PageRouteBuilder"," object from their ",[139,3588,3589],{},"createRoute()",[3559,3591,3592,3593,3595,3596,3598,3599,3601,3602,3604,3605,3607],{"name":364},"Configures the list of ",[139,3594,3570],{},"s for the ",[139,3597,336],{},". An application will have a ",[139,3600,336],{}," (managed by a ",[139,3603,364],{}," widget), which is given a list of ",[139,3606,3570],{},"s.",[3559,3609,3610,3611,3614,3615,3618,3619,3621,3622,3625,3626,3628],{"name":3585},"Has both a ",[139,3612,3613],{},"settings"," parameter and a ",[139,3616,3617],{},"pageBuilder"," parameter. The ",[139,3620,3613],{}," parameter accepts a value of a nullable ",[139,3623,3624],{},"RouteSettings"," object and the ",[139,3627,3617],{}," returns the widget we will eventually show the user.",[3559,3630,3631,3632,3634,3635,3637,3638,393],{"name":3553},"Used to parse the raw URI into an object that ",[139,3633,3478],{}," wants to work with. It, along with the ",[139,3636,3478],{},", are both passed into the ",[139,3639,364],{},[120,3641,3642],{},"Yeah, the Router API is complex.",[243,3644,2862,3646],{"id":3645},"the-routepath",[139,3647,3648],{},"RoutePath",[120,3650,3651,3652,361,3654,3656,3657,3659,3660,3662],{},"Let us just start building out these pieces and see how they work as we go. First, let us create our ",[139,3653,3478],{},[139,3655,3553],{}," objects. We will also need to create a ",[139,3658,3648],{},", which is a representation of the raw URI that the ",[139,3661,3478],{}," will work with, so let us start there:",[475,3664,3667],{"className":477,"code":3665,"filename":3666,"language":480,"meta":106,"style":106},"class ContactRoutePath {\n  final int? id;\n  final bool isUnknown;\n\n  ContactRoutePath.details(this.id) : isUnknown = false;\n\n  ContactRoutePath.home()\n      : id = null,\n        isUnknown = false;\n\n  ContactRoutePath.unknown()\n      : id = null,\n        isUnknown = true;\n\n  bool get isDetailsPage => id != null;\n\n  bool get isHomePage => id == null;\n}\n","Example 8.24 · Example 8.24.dart",[139,3668,3669,3674,3679,3684,3688,3693,3697,3702,3707,3712,3716,3721,3725,3730,3734,3739,3743,3748],{"__ignoreMap":106},[484,3670,3671],{"class":486,"line":487},[484,3672,3673],{},"class ContactRoutePath {\n",[484,3675,3676],{"class":486,"line":493},[484,3677,3678],{},"  final int? id;\n",[484,3680,3681],{"class":486,"line":499},[484,3682,3683],{},"  final bool isUnknown;\n",[484,3685,3686],{"class":486,"line":506},[484,3687,503],{"emptyLinePlaceholder":502},[484,3689,3690],{"class":486,"line":512},[484,3691,3692],{},"  ContactRoutePath.details(this.id) : isUnknown = false;\n",[484,3694,3695],{"class":486,"line":518},[484,3696,503],{"emptyLinePlaceholder":502},[484,3698,3699],{"class":486,"line":524},[484,3700,3701],{},"  ContactRoutePath.home()\n",[484,3703,3704],{"class":486,"line":530},[484,3705,3706],{},"      : id = null,\n",[484,3708,3709],{"class":486,"line":536},[484,3710,3711],{},"        isUnknown = false;\n",[484,3713,3714],{"class":486,"line":542},[484,3715,503],{"emptyLinePlaceholder":502},[484,3717,3718],{"class":486,"line":548},[484,3719,3720],{},"  ContactRoutePath.unknown()\n",[484,3722,3723],{"class":486,"line":554},[484,3724,3706],{},[484,3726,3727],{"class":486,"line":560},[484,3728,3729],{},"        isUnknown = true;\n",[484,3731,3732],{"class":486,"line":566},[484,3733,503],{"emptyLinePlaceholder":502},[484,3735,3736],{"class":486,"line":572},[484,3737,3738],{},"  bool get isDetailsPage => id != null;\n",[484,3740,3741],{"class":486,"line":578},[484,3742,503],{"emptyLinePlaceholder":502},[484,3744,3745],{"class":486,"line":584},[484,3746,3747],{},"  bool get isHomePage => id == null;\n",[484,3749,3750],{"class":486,"line":589},[484,3751,604],{},[120,3753,3754,3755,3758,3759,890,3762,3765,3766,3768],{},"This class takes in a nullable integer ",[139,3756,3757],{},"id",". We will call this class using a constructor later, which could mean calling ",[139,3760,3761],{},"ContactRoutePath.home()",[139,3763,3764],{},"ContactRoutePath.details(id)",". This will make more sense once we put it to use in our ",[139,3767,3478],{},", so let us build that next.",[243,3770,2862,3772],{"id":3771},"the-routerdelegate",[139,3773,3478],{},[475,3775,3778],{"className":477,"code":3776,"filename":3777,"language":480,"meta":106,"style":106},"class ContactRouterDelegate extends RouterDelegate\u003CContactRoutePath>\n    with ChangeNotifier, PopNavigatorRouterDelegateMixin\u003CContactRoutePath> {\n  static const List\u003CContact> contacts = [\n    Contact(name: 'Alice', email: 'alice@flutter.dev'),\n    Contact(name: 'Bob', email: 'bob@flutter.dev'),\n    Contact(name: 'Charlie', email: 'charlie@flutter.dev'),\n  ];\n\n  @override\n  final GlobalKey\u003CNavigatorState> navigatorKey;\n  bool show404 = false;\n  Contact? _selectedContact;\n\n  ContactRouterDelegate() : navigatorKey = GlobalKey\u003CNavigatorState>();\n\n  @override\n  ContactRoutePath get currentConfiguration {\n    if (show404) {\n      return ContactRoutePath.unknown();\n    }\n    return _selectedContact == null\n        ? ContactRoutePath.home()\n        : ContactRoutePath.details(contacts.indexOf(_selectedContact!));\n  }\n\n  @override\n  Widget build(BuildContext context) {\n    return Navigator(\n      key: navigatorKey,\n      pages: [\n        MaterialPage(\n          key: const ValueKey('ContactsListPage'),\n          child: ContactsListScreen(\n            contacts: contacts,\n            onTapped: _handleContactTapped,\n          ),\n        ),\n        if (_selectedContact != null)\n          ContactDetailsPage(contact: _selectedContact!),\n        if (show404)\n          const MaterialPage(\n            key: ValueKey('UnknownPage'),\n            child: UnknownScreen(),\n          ),\n      ],\n      onPopPage: (route, result) {\n        if (!route.didPop(result)) {\n          return false;\n        }\n\n        _selectedContact = null;\n        show404 = false;\n        notifyListeners();\n\n        return true;\n      },\n    );\n  }\n\n  @override\n  Future\u003Cvoid> setNewRoutePath(ContactRoutePath configuration) async {\n    if (configuration.isUnknown) {\n      _selectedContact = null;\n      show404 = true;\n      return;\n    }\n\n    if (!configuration.isDetailsPage) {\n      _selectedContact = null;\n    }\n    if (configuration.id == null) {\n      _selectedContact = null;\n      show404 = false;\n      return;\n    }\n    if (configuration.id! \u003C 0 || configuration.id! > contacts.length - 1) {\n      show404 = true;\n      return;\n    }\n\n    _selectedContact = contacts[configuration.id!];\n\n    show404 = false;\n  }\n\n  void _handleContactTapped(Contact contact) {\n    _selectedContact = contact;\n    notifyListeners();\n  }\n}\n","Example 8.25 · Example 8.25.dart",[139,3779,3780,3785,3790,3795,3800,3805,3810,3815,3819,3823,3828,3833,3838,3842,3847,3851,3855,3860,3865,3870,3874,3879,3884,3889,3893,3897,3901,3905,3910,3915,3920,3925,3930,3935,3940,3945,3949,3953,3958,3963,3968,3973,3978,3983,3987,3992,3997,4002,4007,4012,4016,4021,4026,4031,4035,4040,4045,4049,4053,4057,4061,4066,4071,4076,4081,4086,4090,4094,4099,4103,4107,4112,4116,4121,4125,4129,4134,4138,4142,4146,4150,4155,4159,4164,4168,4172,4177,4182,4187,4191],{"__ignoreMap":106},[484,3781,3782],{"class":486,"line":487},[484,3783,3784],{},"class ContactRouterDelegate extends RouterDelegate\u003CContactRoutePath>\n",[484,3786,3787],{"class":486,"line":493},[484,3788,3789],{},"    with ChangeNotifier, PopNavigatorRouterDelegateMixin\u003CContactRoutePath> {\n",[484,3791,3792],{"class":486,"line":499},[484,3793,3794],{},"  static const List\u003CContact> contacts = [\n",[484,3796,3797],{"class":486,"line":506},[484,3798,3799],{},"    Contact(name: 'Alice', email: 'alice@flutter.dev'),\n",[484,3801,3802],{"class":486,"line":512},[484,3803,3804],{},"    Contact(name: 'Bob', email: 'bob@flutter.dev'),\n",[484,3806,3807],{"class":486,"line":518},[484,3808,3809],{},"    Contact(name: 'Charlie', email: 'charlie@flutter.dev'),\n",[484,3811,3812],{"class":486,"line":524},[484,3813,3814],{},"  ];\n",[484,3816,3817],{"class":486,"line":530},[484,3818,503],{"emptyLinePlaceholder":502},[484,3820,3821],{"class":486,"line":536},[484,3822,509],{},[484,3824,3825],{"class":486,"line":542},[484,3826,3827],{},"  final GlobalKey\u003CNavigatorState> navigatorKey;\n",[484,3829,3830],{"class":486,"line":548},[484,3831,3832],{},"  bool show404 = false;\n",[484,3834,3835],{"class":486,"line":554},[484,3836,3837],{},"  Contact? _selectedContact;\n",[484,3839,3840],{"class":486,"line":560},[484,3841,503],{"emptyLinePlaceholder":502},[484,3843,3844],{"class":486,"line":566},[484,3845,3846],{},"  ContactRouterDelegate() : navigatorKey = GlobalKey\u003CNavigatorState>();\n",[484,3848,3849],{"class":486,"line":572},[484,3850,503],{"emptyLinePlaceholder":502},[484,3852,3853],{"class":486,"line":578},[484,3854,509],{},[484,3856,3857],{"class":486,"line":584},[484,3858,3859],{},"  ContactRoutePath get currentConfiguration {\n",[484,3861,3862],{"class":486,"line":589},[484,3863,3864],{},"    if (show404) {\n",[484,3866,3867],{"class":486,"line":595},[484,3868,3869],{},"      return ContactRoutePath.unknown();\n",[484,3871,3872],{"class":486,"line":601},[484,3873,1698],{},[484,3875,3876],{"class":486,"line":607},[484,3877,3878],{},"    return _selectedContact == null\n",[484,3880,3881],{"class":486,"line":612},[484,3882,3883],{},"        ? ContactRoutePath.home()\n",[484,3885,3886],{"class":486,"line":618},[484,3887,3888],{},"        : ContactRoutePath.details(contacts.indexOf(_selectedContact!));\n",[484,3890,3891],{"class":486,"line":624},[484,3892,598],{},[484,3894,3895],{"class":486,"line":629},[484,3896,503],{"emptyLinePlaceholder":502},[484,3898,3899],{"class":486,"line":634},[484,3900,509],{},[484,3902,3903],{"class":486,"line":639},[484,3904,515],{},[484,3906,3907],{"class":486,"line":644},[484,3908,3909],{},"    return Navigator(\n",[484,3911,3912],{"class":486,"line":649},[484,3913,3914],{},"      key: navigatorKey,\n",[484,3916,3917],{"class":486,"line":655},[484,3918,3919],{},"      pages: [\n",[484,3921,3922],{"class":486,"line":660},[484,3923,3924],{},"        MaterialPage(\n",[484,3926,3927],{"class":486,"line":665},[484,3928,3929],{},"          key: const ValueKey('ContactsListPage'),\n",[484,3931,3932],{"class":486,"line":670},[484,3933,3934],{},"          child: ContactsListScreen(\n",[484,3936,3937],{"class":486,"line":675},[484,3938,3939],{},"            contacts: contacts,\n",[484,3941,3942],{"class":486,"line":681},[484,3943,3944],{},"            onTapped: _handleContactTapped,\n",[484,3946,3947],{"class":486,"line":686},[484,3948,2106],{},[484,3950,3951],{"class":486,"line":692},[484,3952,581],{},[484,3954,3955],{"class":486,"line":697},[484,3956,3957],{},"        if (_selectedContact != null)\n",[484,3959,3960],{"class":486,"line":702},[484,3961,3962],{},"          ContactDetailsPage(contact: _selectedContact!),\n",[484,3964,3965],{"class":486,"line":707},[484,3966,3967],{},"        if (show404)\n",[484,3969,3970],{"class":486,"line":712},[484,3971,3972],{},"          const MaterialPage(\n",[484,3974,3975],{"class":486,"line":2720},[484,3976,3977],{},"            key: ValueKey('UnknownPage'),\n",[484,3979,3980],{"class":486,"line":2726},[484,3981,3982],{},"            child: UnknownScreen(),\n",[484,3984,3985],{"class":486,"line":2732},[484,3986,2106],{},[484,3988,3989],{"class":486,"line":2738},[484,3990,3991],{},"      ],\n",[484,3993,3994],{"class":486,"line":2744},[484,3995,3996],{},"      onPopPage: (route, result) {\n",[484,3998,3999],{"class":486,"line":2750},[484,4000,4001],{},"        if (!route.didPop(result)) {\n",[484,4003,4004],{"class":486,"line":2756},[484,4005,4006],{},"          return false;\n",[484,4008,4009],{"class":486,"line":2761},[484,4010,4011],{},"        }\n",[484,4013,4014],{"class":486,"line":2767},[484,4015,503],{"emptyLinePlaceholder":502},[484,4017,4018],{"class":486,"line":2772},[484,4019,4020],{},"        _selectedContact = null;\n",[484,4022,4023],{"class":486,"line":2777},[484,4024,4025],{},"        show404 = false;\n",[484,4027,4028],{"class":486,"line":2782},[484,4029,4030],{},"        notifyListeners();\n",[484,4032,4033],{"class":486,"line":2787},[484,4034,503],{"emptyLinePlaceholder":502},[484,4036,4037],{"class":486,"line":3232},[484,4038,4039],{},"        return true;\n",[484,4041,4042],{"class":486,"line":3238},[484,4043,4044],{},"      },\n",[484,4046,4047],{"class":486,"line":3243},[484,4048,592],{},[484,4050,4051],{"class":486,"line":3248},[484,4052,598],{},[484,4054,4055],{"class":486,"line":3253},[484,4056,503],{"emptyLinePlaceholder":502},[484,4058,4059],{"class":486,"line":3258},[484,4060,509],{},[484,4062,4063],{"class":486,"line":3263},[484,4064,4065],{},"  Future\u003Cvoid> setNewRoutePath(ContactRoutePath configuration) async {\n",[484,4067,4068],{"class":486,"line":3268},[484,4069,4070],{},"    if (configuration.isUnknown) {\n",[484,4072,4073],{"class":486,"line":3274},[484,4074,4075],{},"      _selectedContact = null;\n",[484,4077,4078],{"class":486,"line":3280},[484,4079,4080],{},"      show404 = true;\n",[484,4082,4083],{"class":486,"line":3285},[484,4084,4085],{},"      return;\n",[484,4087,4088],{"class":486,"line":3291},[484,4089,1698],{},[484,4091,4092],{"class":486,"line":3296},[484,4093,503],{"emptyLinePlaceholder":502},[484,4095,4096],{"class":486,"line":3302},[484,4097,4098],{},"    if (!configuration.isDetailsPage) {\n",[484,4100,4101],{"class":486,"line":3307},[484,4102,4075],{},[484,4104,4105],{"class":486,"line":3312},[484,4106,1698],{},[484,4108,4109],{"class":486,"line":3317},[484,4110,4111],{},"    if (configuration.id == null) {\n",[484,4113,4114],{"class":486,"line":3322},[484,4115,4075],{},[484,4117,4118],{"class":486,"line":3327},[484,4119,4120],{},"      show404 = false;\n",[484,4122,4123],{"class":486,"line":3333},[484,4124,4085],{},[484,4126,4127],{"class":486,"line":3339},[484,4128,1698],{},[484,4130,4131],{"class":486,"line":3345},[484,4132,4133],{},"    if (configuration.id! \u003C 0 || configuration.id! > contacts.length - 1) {\n",[484,4135,4136],{"class":486,"line":3351},[484,4137,4080],{},[484,4139,4140],{"class":486,"line":3357},[484,4141,4085],{},[484,4143,4144],{"class":486,"line":3363},[484,4145,1698],{},[484,4147,4148],{"class":486,"line":3369},[484,4149,503],{"emptyLinePlaceholder":502},[484,4151,4152],{"class":486,"line":3375},[484,4153,4154],{},"    _selectedContact = contacts[configuration.id!];\n",[484,4156,4157],{"class":486,"line":3381},[484,4158,503],{"emptyLinePlaceholder":502},[484,4160,4161],{"class":486,"line":3387},[484,4162,4163],{},"    show404 = false;\n",[484,4165,4166],{"class":486,"line":3392},[484,4167,598],{},[484,4169,4170],{"class":486,"line":3398},[484,4171,503],{"emptyLinePlaceholder":502},[484,4173,4174],{"class":486,"line":3404},[484,4175,4176],{},"  void _handleContactTapped(Contact contact) {\n",[484,4178,4179],{"class":486,"line":3409},[484,4180,4181],{},"    _selectedContact = contact;\n",[484,4183,4184],{"class":486,"line":3415},[484,4185,4186],{},"    notifyListeners();\n",[484,4188,4189],{"class":486,"line":3420},[484,4190,598],{},[484,4192,4193],{"class":486,"line":3425},[484,4194,604],{},[120,4196,4197,4198,4200],{},"This is where our ",[139,4199,3648],{}," comes into play. (This is also where we specify our list of contacts — although, in a production application, these would be stored somewhere else. For the sake of simplicity, we are just going to specify a static list of contacts, though.)",[132,4202,4203,4229],{},[120,4204,4205,341,4207,4210,4211,4214,4215,4218,4219,4222,4223,727,4225,4228],{},[111,4206,1110],{},[139,4208,4209],{},"onPopPage"," is deprecated: \"This is deprecated and replaced by onDidRemovePage\" (Flutter, n.d.-b), deprecated after Flutter 3.16, and ",[139,4212,4213],{},"flutter analyze"," reports it. ",[139,4216,4217],{},"onDidRemovePage(page)"," runs after a page has left the stack, whether it was popped (back button) or dropped from ",[139,4220,4221],{},"pages"," (a new URL), so it must reset only the state of the page that is still current, or a new deep link from ",[139,4224,2895],{},[139,4226,4227],{},"\u002Fcontact\u002F1"," would clear the newly selected contact. The runnable copy uses:",[475,4230,4232],{"className":477,"code":4231,"language":480,"meta":106,"style":106},"onDidRemovePage: (page) {\n  if (page is ContactDetailsPage && page.contact == _selectedContact) {\n    _selectedContact = null;\n  } else if (page.key == const ValueKey('UnknownPage') && show404) {\n    show404 = false;\n  } else {\n    return;\n  }\n  notifyListeners();\n},\n",[139,4233,4234,4239,4244,4249,4254,4258,4263,4268,4272,4277],{"__ignoreMap":106},[484,4235,4236],{"class":486,"line":487},[484,4237,4238],{},"onDidRemovePage: (page) {\n",[484,4240,4241],{"class":486,"line":493},[484,4242,4243],{},"  if (page is ContactDetailsPage && page.contact == _selectedContact) {\n",[484,4245,4246],{"class":486,"line":499},[484,4247,4248],{},"    _selectedContact = null;\n",[484,4250,4251],{"class":486,"line":506},[484,4252,4253],{},"  } else if (page.key == const ValueKey('UnknownPage') && show404) {\n",[484,4255,4256],{"class":486,"line":512},[484,4257,4163],{},[484,4259,4260],{"class":486,"line":518},[484,4261,4262],{},"  } else {\n",[484,4264,4265],{"class":486,"line":524},[484,4266,4267],{},"    return;\n",[484,4269,4270],{"class":486,"line":530},[484,4271,598],{},[484,4273,4274],{"class":486,"line":536},[484,4275,4276],{},"  notifyListeners();\n",[484,4278,4279],{"class":486,"line":542},[484,4280,1191],{},[120,4282,2862,4283,4285,4286,4288,4289,4291],{},[139,4284,3478],{}," is what returns the ",[139,4287,336],{}," widget, which we discussed earlier. There are two flows that the ",[139,4290,3478],{}," controls:",[171,4293,4294,4334],{},[174,4295,4298,4299,4302,4303,4306,4307,4309,4310,4313,4314,4317,4318,4320,4321,4324,4325,1978,4328,4331,4332,393],{"icon":4296,"title":4297},"i-lucide-monitor-down","Platform to user","When a URI (as ",[139,4300,4301],{},"RouteInformation",") comes (through ",[139,4304,4305],{},"RouteInformationProvider",") to our app and ",[139,4308,3553],{}," parses it into our ",[139,4311,4312],{},"ContactRoutePath",", then the ",[139,4315,4316],{},"setNewRoutePath()"," is called where ",[139,4319,3478],{}," configures the ",[228,4322,4323],{},"routing state"," (",[139,4326,4327],{},"show404",[139,4329,4330],{},"_selectedContact",", and so on) to match the incoming route information and build the ",[139,4333,336],{},[174,4335,4338,4339,4341,4342,4345,4346,4348,4349,4352,4353,4355,4356,4358,4359,4361],{"icon":4336,"title":4337},"i-lucide-monitor-up","User to platform","When we navigate within the app (for example, with ",[139,4340,3534],{},"), the routing state is first updated and ",[139,4343,4344],{},"notifyListeners"," is called. This will trigger both a rebuild of ",[139,4347,336],{}," and cause the platform to fetch the ",[139,4350,4351],{},"currentConfiguration"," (for example, causing the browser to update the URI). Here, the ",[139,4354,3553],{}," is again used to restore (parse back) the current ",[139,4357,4312],{}," into a ",[139,4360,4301],{}," that the platform can understand.",[243,4363,2862,4365],{"id":4364},"the-routeinformationparser",[139,4366,3553],{},[120,4368,4369,4370,4372,4373,4375],{},"Now, let us implement the ",[139,4371,3553],{},", which is the object that converts the raw URI back and forth into something that the ",[139,4374,3478],{}," understands:",[475,4377,4380],{"className":477,"code":4378,"filename":4379,"language":480,"meta":106,"style":106},"class ContactRouteInformationParser\n    extends RouteInformationParser\u003CContactRoutePath> {\n  @override\n  Future\u003CContactRoutePath> parseRouteInformation(\n    RouteInformation routeInformation,\n  ) async {\n    final Uri uri = Uri.parse(routeInformation.location!);\n    \u002F\u002F Handle '\u002F'\n    if (uri.pathSegments.isEmpty) {\n      return ContactRoutePath.home();\n    }\n\n    \u002F\u002F Handle '\u002Fcontact\u002F:id'\n    if (uri.pathSegments.length == 2) {\n      if (uri.pathSegments[0] != 'contact') return ContactRoutePath.unknown();\n      String remaining = uri.pathSegments[1];\n      int? id = int.tryParse(remaining);\n      if (id == null) return ContactRoutePath.unknown();\n      return ContactRoutePath.details(id);\n    }\n\n    \u002F\u002F Handle unknown routes\n    return ContactRoutePath.unknown();\n  }\n\n  @override\n  RouteInformation? restoreRouteInformation(ContactRoutePath configuration) {\n    if (configuration.isUnknown) {\n      return const RouteInformation(location: '\u002F404');\n    }\n    if (configuration.isHomePage) {\n      return const RouteInformation(location: '\u002F');\n    }\n    if (configuration.isDetailsPage) {\n      return RouteInformation(location: '\u002Fcontact\u002F${configuration.id}');\n    }\n    return null;\n  }\n}\n","Example 8.26 · Example 8.26.dart",[139,4381,4382,4387,4392,4396,4401,4406,4411,4416,4421,4426,4431,4435,4439,4444,4449,4454,4459,4464,4469,4474,4478,4482,4487,4492,4496,4500,4504,4509,4513,4518,4522,4527,4532,4536,4541,4546,4550,4554,4558],{"__ignoreMap":106},[484,4383,4384],{"class":486,"line":487},[484,4385,4386],{},"class ContactRouteInformationParser\n",[484,4388,4389],{"class":486,"line":493},[484,4390,4391],{},"    extends RouteInformationParser\u003CContactRoutePath> {\n",[484,4393,4394],{"class":486,"line":499},[484,4395,509],{},[484,4397,4398],{"class":486,"line":506},[484,4399,4400],{},"  Future\u003CContactRoutePath> parseRouteInformation(\n",[484,4402,4403],{"class":486,"line":512},[484,4404,4405],{},"    RouteInformation routeInformation,\n",[484,4407,4408],{"class":486,"line":518},[484,4409,4410],{},"  ) async {\n",[484,4412,4413],{"class":486,"line":524},[484,4414,4415],{},"    final Uri uri = Uri.parse(routeInformation.location!);\n",[484,4417,4418],{"class":486,"line":530},[484,4419,4420],{},"    \u002F\u002F Handle '\u002F'\n",[484,4422,4423],{"class":486,"line":536},[484,4424,4425],{},"    if (uri.pathSegments.isEmpty) {\n",[484,4427,4428],{"class":486,"line":542},[484,4429,4430],{},"      return ContactRoutePath.home();\n",[484,4432,4433],{"class":486,"line":548},[484,4434,1698],{},[484,4436,4437],{"class":486,"line":554},[484,4438,503],{"emptyLinePlaceholder":502},[484,4440,4441],{"class":486,"line":560},[484,4442,4443],{},"    \u002F\u002F Handle '\u002Fcontact\u002F:id'\n",[484,4445,4446],{"class":486,"line":566},[484,4447,4448],{},"    if (uri.pathSegments.length == 2) {\n",[484,4450,4451],{"class":486,"line":572},[484,4452,4453],{},"      if (uri.pathSegments[0] != 'contact') return ContactRoutePath.unknown();\n",[484,4455,4456],{"class":486,"line":578},[484,4457,4458],{},"      String remaining = uri.pathSegments[1];\n",[484,4460,4461],{"class":486,"line":584},[484,4462,4463],{},"      int? id = int.tryParse(remaining);\n",[484,4465,4466],{"class":486,"line":589},[484,4467,4468],{},"      if (id == null) return ContactRoutePath.unknown();\n",[484,4470,4471],{"class":486,"line":595},[484,4472,4473],{},"      return ContactRoutePath.details(id);\n",[484,4475,4476],{"class":486,"line":601},[484,4477,1698],{},[484,4479,4480],{"class":486,"line":607},[484,4481,503],{"emptyLinePlaceholder":502},[484,4483,4484],{"class":486,"line":612},[484,4485,4486],{},"    \u002F\u002F Handle unknown routes\n",[484,4488,4489],{"class":486,"line":618},[484,4490,4491],{},"    return ContactRoutePath.unknown();\n",[484,4493,4494],{"class":486,"line":624},[484,4495,598],{},[484,4497,4498],{"class":486,"line":629},[484,4499,503],{"emptyLinePlaceholder":502},[484,4501,4502],{"class":486,"line":634},[484,4503,509],{},[484,4505,4506],{"class":486,"line":639},[484,4507,4508],{},"  RouteInformation? restoreRouteInformation(ContactRoutePath configuration) {\n",[484,4510,4511],{"class":486,"line":644},[484,4512,4070],{},[484,4514,4515],{"class":486,"line":649},[484,4516,4517],{},"      return const RouteInformation(location: '\u002F404');\n",[484,4519,4520],{"class":486,"line":655},[484,4521,1698],{},[484,4523,4524],{"class":486,"line":660},[484,4525,4526],{},"    if (configuration.isHomePage) {\n",[484,4528,4529],{"class":486,"line":665},[484,4530,4531],{},"      return const RouteInformation(location: '\u002F');\n",[484,4533,4534],{"class":486,"line":670},[484,4535,1698],{},[484,4537,4538],{"class":486,"line":675},[484,4539,4540],{},"    if (configuration.isDetailsPage) {\n",[484,4542,4543],{"class":486,"line":681},[484,4544,4545],{},"      return RouteInformation(location: '\u002Fcontact\u002F${configuration.id}');\n",[484,4547,4548],{"class":486,"line":686},[484,4549,1698],{},[484,4551,4552],{"class":486,"line":692},[484,4553,1764],{},[484,4555,4556],{"class":486,"line":697},[484,4557,598],{},[484,4559,4560],{"class":486,"line":702},[484,4561,604],{},[120,4563,2862,4564,4567,4568,4571,4572,4574],{},[139,4565,4566],{},"parseRouteInformation"," method is what does the heavy lifting of pulling the parameters out of the URI, whereas the ",[139,4569,4570],{},"restoreRouteInformation"," method is what returns the ",[139,4573,4301],{}," that is used to set the new URI.",[132,4576,4577,341,4579,4582,4583,4586,4587,4589,4590,4593,4594,4597,4598,4601,4602,4605],{},[111,4578,1110],{},[139,4580,4581],{},"RouteInformation.location"," is deprecated: \"Use uri instead. This feature was deprecated after v3.8.0-3.0.pre.\" (Flutter, n.d.-c). ",[139,4584,4585],{},"location"," is also no longer nullable, so the ",[139,4588,994],{}," only produces a warning. Read the parsed ",[139,4591,4592],{},"Uri"," directly with ",[139,4595,4596],{},"final Uri uri = routeInformation.uri;",", and create the objects with ",[139,4599,4600],{},"RouteInformation(uri: Uri.parse('\u002F404'))"," (these can no longer be ",[139,4603,4604],{},"const","), as the runnable copy does.",[243,4607,4609],{"id":4608},"wiring-it-into-the-app","Wiring it into the app",[120,4611,4612,4613,4616],{},"That is a ",[228,4614,4615],{},"ton"," of boilerplate code, but all of it is necessary! Let us update our application to use it:",[475,4618,4621],{"className":477,"code":4619,"filename":4620,"language":480,"meta":106,"style":106},"class _ContactsAppState extends State\u003CContactsApp> {\n  final ContactRouterDelegate _routerDelegate = ContactRouterDelegate();\n  final ContactRouteInformationParser _routeInformationParser =\n      ContactRouteInformationParser();\n\n  @override\n  Widget build(BuildContext context) {\n    return MaterialApp.router(\n      title: 'Contacts App',\n      routerDelegate: _routerDelegate,\n      routeInformationParser: _routeInformationParser,\n    );\n  }\n}\n","Example 8.27 · Example 8.27.dart",[139,4622,4623,4627,4632,4637,4642,4646,4650,4654,4659,4663,4668,4673,4677,4681],{"__ignoreMap":106},[484,4624,4625],{"class":486,"line":487},[484,4626,3047],{},[484,4628,4629],{"class":486,"line":493},[484,4630,4631],{},"  final ContactRouterDelegate _routerDelegate = ContactRouterDelegate();\n",[484,4633,4634],{"class":486,"line":499},[484,4635,4636],{},"  final ContactRouteInformationParser _routeInformationParser =\n",[484,4638,4639],{"class":486,"line":506},[484,4640,4641],{},"      ContactRouteInformationParser();\n",[484,4643,4644],{"class":486,"line":512},[484,4645,503],{"emptyLinePlaceholder":502},[484,4647,4648],{"class":486,"line":518},[484,4649,509],{},[484,4651,4652],{"class":486,"line":524},[484,4653,515],{},[484,4655,4656],{"class":486,"line":530},[484,4657,4658],{},"    return MaterialApp.router(\n",[484,4660,4661],{"class":486,"line":536},[484,4662,3069],{},[484,4664,4665],{"class":486,"line":542},[484,4666,4667],{},"      routerDelegate: _routerDelegate,\n",[484,4669,4670],{"class":486,"line":548},[484,4671,4672],{},"      routeInformationParser: _routeInformationParser,\n",[484,4674,4675],{"class":486,"line":554},[484,4676,592],{},[484,4678,4679],{"class":486,"line":560},[484,4680,598],{},[484,4682,4683],{"class":486,"line":566},[484,4684,604],{},[120,4686,4687],{},"At this point, everything should work as expected — the list of contacts, tapping to view the contact details, the URI updating, the back button — everything.",[243,4689,4691],{"id":4690},"a-custom-page-transition","A custom page transition",[120,4693,4694],{},"There is one more tweak we can make to this. Let us change the page transition:",[475,4696,4699],{"className":477,"code":4697,"filename":4698,"language":480,"meta":106,"style":106},"class ContactDetailsPage extends Page {\n  final Contact contact;\n\n  ContactDetailsPage({\n    required this.contact,\n  }) : super(key: ValueKey(contact));\n\n  @override\n  Route createRoute(BuildContext context) {\n    return PageRouteBuilder(\n      settings: this,\n      pageBuilder: (context, animation, animation2) {\n        final tween = Tween(\n          begin: const Offset(1.0, 0),\n          end: Offset.zero,\n        );\n        final curveTween = CurveTween(\n          curve: Curves.easeInOut,\n        );\n        return SlideTransition(\n          position: animation.drive(curveTween).drive(tween),\n          child: ContactDetailsScreen(\n            key: ValueKey(contact),\n            contact: contact,\n          ),\n        );\n      },\n    );\n  }\n}\n","Example 8.28 · Example 8.28.dart",[139,4700,4701,4706,4710,4714,4719,4723,4728,4732,4736,4741,4746,4751,4756,4761,4766,4771,4776,4781,4786,4790,4795,4800,4805,4810,4815,4819,4823,4827,4831,4835],{"__ignoreMap":106},[484,4702,4703],{"class":486,"line":487},[484,4704,4705],{},"class ContactDetailsPage extends Page {\n",[484,4707,4708],{"class":486,"line":493},[484,4709,3277],{},[484,4711,4712],{"class":486,"line":499},[484,4713,503],{"emptyLinePlaceholder":502},[484,4715,4716],{"class":486,"line":506},[484,4717,4718],{},"  ContactDetailsPage({\n",[484,4720,4721],{"class":486,"line":512},[484,4722,3299],{},[484,4724,4725],{"class":486,"line":518},[484,4726,4727],{},"  }) : super(key: ValueKey(contact));\n",[484,4729,4730],{"class":486,"line":524},[484,4731,503],{"emptyLinePlaceholder":502},[484,4733,4734],{"class":486,"line":530},[484,4735,509],{},[484,4737,4738],{"class":486,"line":536},[484,4739,4740],{},"  Route createRoute(BuildContext context) {\n",[484,4742,4743],{"class":486,"line":542},[484,4744,4745],{},"    return PageRouteBuilder(\n",[484,4747,4748],{"class":486,"line":548},[484,4749,4750],{},"      settings: this,\n",[484,4752,4753],{"class":486,"line":554},[484,4754,4755],{},"      pageBuilder: (context, animation, animation2) {\n",[484,4757,4758],{"class":486,"line":560},[484,4759,4760],{},"        final tween = Tween(\n",[484,4762,4763],{"class":486,"line":566},[484,4764,4765],{},"          begin: const Offset(1.0, 0),\n",[484,4767,4768],{"class":486,"line":572},[484,4769,4770],{},"          end: Offset.zero,\n",[484,4772,4773],{"class":486,"line":578},[484,4774,4775],{},"        );\n",[484,4777,4778],{"class":486,"line":584},[484,4779,4780],{},"        final curveTween = CurveTween(\n",[484,4782,4783],{"class":486,"line":589},[484,4784,4785],{},"          curve: Curves.easeInOut,\n",[484,4787,4788],{"class":486,"line":595},[484,4789,4775],{},[484,4791,4792],{"class":486,"line":601},[484,4793,4794],{},"        return SlideTransition(\n",[484,4796,4797],{"class":486,"line":607},[484,4798,4799],{},"          position: animation.drive(curveTween).drive(tween),\n",[484,4801,4802],{"class":486,"line":612},[484,4803,4804],{},"          child: ContactDetailsScreen(\n",[484,4806,4807],{"class":486,"line":618},[484,4808,4809],{},"            key: ValueKey(contact),\n",[484,4811,4812],{"class":486,"line":624},[484,4813,4814],{},"            contact: contact,\n",[484,4816,4817],{"class":486,"line":629},[484,4818,2106],{},[484,4820,4821],{"class":486,"line":634},[484,4822,4775],{},[484,4824,4825],{"class":486,"line":639},[484,4826,4044],{},[484,4828,4829],{"class":486,"line":644},[484,4830,592],{},[484,4832,4833],{"class":486,"line":649},[484,4834,598],{},[484,4836,4837],{"class":486,"line":655},[484,4838,604],{},[120,4840,4841,341,4843,4846],{},[228,4842,804],{},[139,4844,4845],{},"examples\u002Fflutter_for_jobseekers_ch08\u002Flib\u002Fmain.dart"," (the whole Router API app; its tests open deep links, the 404 page and press the system back button)",[120,4848,4849,4850,4852,4853,4856],{},"Here, the ",[139,4851,3617],{}," ends up building a ",[139,4854,4855],{},"SlideTransition"," animation instead of the default animation.",[276,4858,4859,4860,4862],{},"What other animations or transitions could you use instead of a ",[139,4861,4855],{},"?",[120,4864,4865],{},"The Router API is, as we have seen, significantly more complex than Navigator 1.0. Although we moved quickly through it and did not examine every line of code (which could have been its own book!), we do have a working example from which we can build upon later and study further.",[166,4867,205],{"id":4868},"using-packages-to-help-with-routing",[120,4870,4871,4872,4875,4876,4879],{},"Expectedly, a lot of packages emerged that try to simplify the usage of the Router API. Let us see an implementation of the same app using one of them — ",[111,4873,4874],{},"Beamer",", which was created by Sandro Lovnički (",[139,4877,4878],{},"@slovnicki",").",[132,4881,4882],{},"As we will see, a lot of things we needed to implement by hand before are abstracted out for us in Beamer. In fact, all we need to define are the routes we want to handle and, optionally, how we want to handle them. Beamer also has an advanced API that we could use, but that is a topic for another day.",[120,4884,4885],{},"Here is the same application we just wrote using the Router API, this time written using Beamer as a basis:",[475,4887,4890],{"className":477,"code":4888,"filename":4889,"language":480,"meta":106,"style":106},"import 'package:beamer\u002Fbeamer.dart';\nimport 'package:flutter\u002Fmaterial.dart';\n\nvoid main() {\n  runApp(const ContactsApp());\n}\n\nclass Contact {\n  final String name;\n  final String email;\n\n  const Contact({\n    required this.name,\n    required this.email,\n  });\n}\n\nclass ContactDetailsScreen extends StatelessWidget {\n  final Contact contact;\n\n  const ContactDetailsScreen({super.key, required this.contact});\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      body: SafeArea(\n        child: Padding(\n          padding: const EdgeInsets.all(8.0),\n          child: Column(\n            crossAxisAlignment: CrossAxisAlignment.start,\n            children: [\n              Text(\n                contact.name,\n                style: Theme.of(context).textTheme.headline6,\n              ),\n              Text(\n                contact.email,\n                style: Theme.of(context).textTheme.subtitle1,\n              ),\n            ],\n          ),\n        ),\n      ),\n    );\n  }\n}\n\nclass ContactsApp extends StatefulWidget {\n  const ContactsApp({super.key});\n\n  @override\n  State\u003CStatefulWidget> createState() => _ContactsAppState();\n}\n\nclass ContactsListScreen extends StatelessWidget {\n  final List\u003CContact> contacts;\n  final ValueChanged\u003CContact> onTapped;\n\n  const ContactsListScreen({\n    super.key,\n    required this.contacts,\n    required this.onTapped,\n  });\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      body: ListView(\n        children: [\n          for (final Contact contact in contacts)\n            ListTile(\n              title: Text(contact.name),\n              subtitle: Text(contact.email),\n              onTap: () => onTapped(contact),\n            )\n        ],\n      ),\n    );\n  }\n}\n\nclass UnknownScreen extends StatelessWidget {\n  const UnknownScreen({super.key});\n\n  @override\n  Widget build(BuildContext context) {\n    return const Scaffold(\n      body: Center(\n        child: Text('Oops.'),\n      ),\n    );\n  }\n}\n\nclass _ContactsAppState extends State\u003CContactsApp> {\n  static const List\u003CContact> contacts = [\n    Contact(name: 'Alice', email: 'alice@flutter.dev'),\n    Contact(name: 'Bob', email: 'bob@flutter.dev'),\n    Contact(name: 'Charlie', email: 'charlie@flutter.dev'),\n  ];\n\n  final _routerDelegate = BeamerDelegate(\n    setBrowserTabTitle: false,\n    notFoundRedirectNamed: '\u002F404',\n    locationBuilder: RoutesLocationBuilder(\n      routes: {\n        '\u002F': (context, _, __) => ContactsListScreen(\n              contacts: contacts,\n              onTapped: (contact) => context.beamToNamed(\n                '\u002Fcontact\u002F${contacts.indexOf(contact)}',\n              ),\n            ),\n        '\u002Fcontact\u002F:id': (_, state, __) {\n          final id = int.parse(state.pathParameters['id']!);\n          return BeamPage(\n            key: ValueKey('contact-$id'),\n            type: BeamPageType.slideRightTransition,\n            popToNamed: '\u002F',\n            child: ContactDetailsScreen(contact: contacts[id]),\n          );\n        },\n        '\u002F404': (_, __, ___) => const UnknownScreen(),\n      },\n    ),\n    guards: [\n      BeamGuard(\n        pathPatterns: ['\u002Fcontact\u002F*'],\n        check: (_, beamLocation) {\n          final beamState = beamLocation.state as BeamState;\n          final idParameter = beamState.pathParameters['id'];\n          if (idParameter != null) {\n            final id = int.tryParse(idParameter);\n            if (id == null || id \u003C 0 || id >= contacts.length) {\n              return false;\n            }\n          }\n          return true;\n        },\n        beamToNamed: (_, __) => '\u002F404',\n      )\n    ],\n  );\n  final _routeInformationParser = BeamerParser();\n\n  @override\n  Widget build(BuildContext context) {\n    return MaterialApp.router(\n      title: 'Contacts App',\n      routerDelegate: _routerDelegate,\n      routeInformationParser: _routeInformationParser,\n    );\n  }\n}\n","Example 8.29 · Example 8.29.dart",[139,4891,4892,4897,4901,4905,4909,4913,4917,4921,4925,4929,4933,4937,4941,4945,4949,4953,4957,4961,4965,4969,4973,4978,4982,4986,4990,4994,4998,5002,5006,5010,5014,5018,5022,5026,5030,5034,5038,5042,5046,5050,5054,5058,5062,5066,5070,5074,5078,5082,5086,5090,5094,5098,5102,5106,5110,5114,5118,5122,5126,5130,5134,5138,5142,5146,5150,5154,5158,5162,5166,5170,5174,5178,5182,5186,5190,5194,5198,5202,5206,5210,5214,5218,5223,5228,5232,5236,5240,5245,5249,5254,5258,5262,5266,5270,5275,5280,5285,5290,5295,5300,5305,5310,5316,5322,5328,5334,5340,5346,5352,5358,5364,5369,5374,5380,5386,5392,5398,5404,5410,5416,5421,5426,5432,5437,5442,5448,5454,5460,5466,5472,5478,5484,5490,5496,5502,5508,5514,5520,5525,5531,5537,5543,5548,5554,5559,5564,5569,5574,5579,5584,5589,5594,5599],{"__ignoreMap":106},[484,4893,4894],{"class":486,"line":487},[484,4895,4896],{},"import 'package:beamer\u002Fbeamer.dart';\n",[484,4898,4899],{"class":486,"line":493},[484,4900,2989],{},[484,4902,4903],{"class":486,"line":499},[484,4904,503],{"emptyLinePlaceholder":502},[484,4906,4907],{"class":486,"line":506},[484,4908,2998],{},[484,4910,4911],{"class":486,"line":512},[484,4912,3003],{},[484,4914,4915],{"class":486,"line":518},[484,4916,604],{},[484,4918,4919],{"class":486,"line":524},[484,4920,503],{"emptyLinePlaceholder":502},[484,4922,4923],{"class":486,"line":530},[484,4924,3095],{},[484,4926,4927],{"class":486,"line":536},[484,4928,1281],{},[484,4930,4931],{"class":486,"line":542},[484,4932,3104],{},[484,4934,4935],{"class":486,"line":548},[484,4936,503],{"emptyLinePlaceholder":502},[484,4938,4939],{"class":486,"line":554},[484,4940,3113],{},[484,4942,4943],{"class":486,"line":560},[484,4944,3118],{},[484,4946,4947],{"class":486,"line":566},[484,4948,3123],{},[484,4950,4951],{"class":486,"line":572},[484,4952,3128],{},[484,4954,4955],{"class":486,"line":578},[484,4956,604],{},[484,4958,4959],{"class":486,"line":584},[484,4960,503],{"emptyLinePlaceholder":502},[484,4962,4963],{"class":486,"line":589},[484,4964,3271],{},[484,4966,4967],{"class":486,"line":595},[484,4968,3277],{},[484,4970,4971],{"class":486,"line":601},[484,4972,503],{"emptyLinePlaceholder":502},[484,4974,4975],{"class":486,"line":607},[484,4976,4977],{},"  const ContactDetailsScreen({super.key, required this.contact});\n",[484,4979,4980],{"class":486,"line":612},[484,4981,503],{"emptyLinePlaceholder":502},[484,4983,4984],{"class":486,"line":618},[484,4985,509],{},[484,4987,4988],{"class":486,"line":624},[484,4989,515],{},[484,4991,4992],{"class":486,"line":629},[484,4993,521],{},[484,4995,4996],{"class":486,"line":634},[484,4997,3330],{},[484,4999,5000],{"class":486,"line":639},[484,5001,3336],{},[484,5003,5004],{"class":486,"line":644},[484,5005,3342],{},[484,5007,5008],{"class":486,"line":649},[484,5009,3348],{},[484,5011,5012],{"class":486,"line":655},[484,5013,3354],{},[484,5015,5016],{"class":486,"line":660},[484,5017,3360],{},[484,5019,5020],{"class":486,"line":665},[484,5021,3366],{},[484,5023,5024],{"class":486,"line":670},[484,5025,3372],{},[484,5027,5028],{"class":486,"line":675},[484,5029,3378],{},[484,5031,5032],{"class":486,"line":681},[484,5033,3384],{},[484,5035,5036],{"class":486,"line":686},[484,5037,3366],{},[484,5039,5040],{"class":486,"line":692},[484,5041,3395],{},[484,5043,5044],{"class":486,"line":697},[484,5045,3401],{},[484,5047,5048],{"class":486,"line":702},[484,5049,3384],{},[484,5051,5052],{"class":486,"line":707},[484,5053,3412],{},[484,5055,5056],{"class":486,"line":712},[484,5057,2106],{},[484,5059,5060],{"class":486,"line":2720},[484,5061,581],{},[484,5063,5064],{"class":486,"line":2726},[484,5065,539],{},[484,5067,5068],{"class":486,"line":2732},[484,5069,592],{},[484,5071,5072],{"class":486,"line":2738},[484,5073,598],{},[484,5075,5076],{"class":486,"line":2744},[484,5077,604],{},[484,5079,5080],{"class":486,"line":2750},[484,5081,503],{"emptyLinePlaceholder":502},[484,5083,5084],{"class":486,"line":2756},[484,5085,3016],{},[484,5087,5088],{"class":486,"line":2761},[484,5089,3021],{},[484,5091,5092],{"class":486,"line":2767},[484,5093,503],{"emptyLinePlaceholder":502},[484,5095,5096],{"class":486,"line":2772},[484,5097,509],{},[484,5099,5100],{"class":486,"line":2777},[484,5101,3034],{},[484,5103,5104],{"class":486,"line":2782},[484,5105,604],{},[484,5107,5108],{"class":486,"line":2787},[484,5109,503],{"emptyLinePlaceholder":502},[484,5111,5112],{"class":486,"line":3232},[484,5113,3141],{},[484,5115,5116],{"class":486,"line":3238},[484,5117,3146],{},[484,5119,5120],{"class":486,"line":3243},[484,5121,3151],{},[484,5123,5124],{"class":486,"line":3248},[484,5125,503],{"emptyLinePlaceholder":502},[484,5127,5128],{"class":486,"line":3253},[484,5129,3160],{},[484,5131,5132],{"class":486,"line":3258},[484,5133,3165],{},[484,5135,5136],{"class":486,"line":3263},[484,5137,3170],{},[484,5139,5140],{"class":486,"line":3268},[484,5141,3175],{},[484,5143,5144],{"class":486,"line":3274},[484,5145,3128],{},[484,5147,5148],{"class":486,"line":3280},[484,5149,503],{"emptyLinePlaceholder":502},[484,5151,5152],{"class":486,"line":3285},[484,5153,509],{},[484,5155,5156],{"class":486,"line":3291},[484,5157,515],{},[484,5159,5160],{"class":486,"line":3296},[484,5161,521],{},[484,5163,5164],{"class":486,"line":3302},[484,5165,3200],{},[484,5167,5168],{"class":486,"line":3307},[484,5169,2071],{},[484,5171,5172],{"class":486,"line":3312},[484,5173,3209],{},[484,5175,5176],{"class":486,"line":3317},[484,5177,3214],{},[484,5179,5180],{"class":486,"line":3322},[484,5181,3219],{},[484,5183,5184],{"class":486,"line":3327},[484,5185,3224],{},[484,5187,5188],{"class":486,"line":3333},[484,5189,3229],{},[484,5191,5192],{"class":486,"line":3339},[484,5193,3235],{},[484,5195,5196],{"class":486,"line":3345},[484,5197,2111],{},[484,5199,5200],{"class":486,"line":3351},[484,5201,539],{},[484,5203,5204],{"class":486,"line":3357},[484,5205,592],{},[484,5207,5208],{"class":486,"line":3363},[484,5209,598],{},[484,5211,5212],{"class":486,"line":3369},[484,5213,604],{},[484,5215,5216],{"class":486,"line":3375},[484,5217,503],{"emptyLinePlaceholder":502},[484,5219,5220],{"class":486,"line":3381},[484,5221,5222],{},"class UnknownScreen extends StatelessWidget {\n",[484,5224,5225],{"class":486,"line":3387},[484,5226,5227],{},"  const UnknownScreen({super.key});\n",[484,5229,5230],{"class":486,"line":3392},[484,5231,503],{"emptyLinePlaceholder":502},[484,5233,5234],{"class":486,"line":3398},[484,5235,509],{},[484,5237,5238],{"class":486,"line":3404},[484,5239,515],{},[484,5241,5242],{"class":486,"line":3409},[484,5243,5244],{},"    return const Scaffold(\n",[484,5246,5247],{"class":486,"line":3415},[484,5248,545],{},[484,5250,5251],{"class":486,"line":3420},[484,5252,5253],{},"        child: Text('Oops.'),\n",[484,5255,5256],{"class":486,"line":3425},[484,5257,539],{},[484,5259,5260],{"class":486,"line":3430},[484,5261,592],{},[484,5263,5264],{"class":486,"line":3435},[484,5265,598],{},[484,5267,5268],{"class":486,"line":3440},[484,5269,604],{},[484,5271,5273],{"class":486,"line":5272},94,[484,5274,503],{"emptyLinePlaceholder":502},[484,5276,5278],{"class":486,"line":5277},95,[484,5279,3047],{},[484,5281,5283],{"class":486,"line":5282},96,[484,5284,3794],{},[484,5286,5288],{"class":486,"line":5287},97,[484,5289,3799],{},[484,5291,5293],{"class":486,"line":5292},98,[484,5294,3804],{},[484,5296,5298],{"class":486,"line":5297},99,[484,5299,3809],{},[484,5301,5303],{"class":486,"line":5302},100,[484,5304,3814],{},[484,5306,5308],{"class":486,"line":5307},101,[484,5309,503],{"emptyLinePlaceholder":502},[484,5311,5313],{"class":486,"line":5312},102,[484,5314,5315],{},"  final _routerDelegate = BeamerDelegate(\n",[484,5317,5319],{"class":486,"line":5318},103,[484,5320,5321],{},"    setBrowserTabTitle: false,\n",[484,5323,5325],{"class":486,"line":5324},104,[484,5326,5327],{},"    notFoundRedirectNamed: '\u002F404',\n",[484,5329,5331],{"class":486,"line":5330},105,[484,5332,5333],{},"    locationBuilder: RoutesLocationBuilder(\n",[484,5335,5337],{"class":486,"line":5336},106,[484,5338,5339],{},"      routes: {\n",[484,5341,5343],{"class":486,"line":5342},107,[484,5344,5345],{},"        '\u002F': (context, _, __) => ContactsListScreen(\n",[484,5347,5349],{"class":486,"line":5348},108,[484,5350,5351],{},"              contacts: contacts,\n",[484,5353,5355],{"class":486,"line":5354},109,[484,5356,5357],{},"              onTapped: (contact) => context.beamToNamed(\n",[484,5359,5361],{"class":486,"line":5360},110,[484,5362,5363],{},"                '\u002Fcontact\u002F${contacts.indexOf(contact)}',\n",[484,5365,5367],{"class":486,"line":5366},111,[484,5368,3384],{},[484,5370,5372],{"class":486,"line":5371},112,[484,5373,2717],{},[484,5375,5377],{"class":486,"line":5376},113,[484,5378,5379],{},"        '\u002Fcontact\u002F:id': (_, state, __) {\n",[484,5381,5383],{"class":486,"line":5382},114,[484,5384,5385],{},"          final id = int.parse(state.pathParameters['id']!);\n",[484,5387,5389],{"class":486,"line":5388},115,[484,5390,5391],{},"          return BeamPage(\n",[484,5393,5395],{"class":486,"line":5394},116,[484,5396,5397],{},"            key: ValueKey('contact-$id'),\n",[484,5399,5401],{"class":486,"line":5400},117,[484,5402,5403],{},"            type: BeamPageType.slideRightTransition,\n",[484,5405,5407],{"class":486,"line":5406},118,[484,5408,5409],{},"            popToNamed: '\u002F',\n",[484,5411,5413],{"class":486,"line":5412},119,[484,5414,5415],{},"            child: ContactDetailsScreen(contact: contacts[id]),\n",[484,5417,5419],{"class":486,"line":5418},120,[484,5420,1683],{},[484,5422,5424],{"class":486,"line":5423},121,[484,5425,1688],{},[484,5427,5429],{"class":486,"line":5428},122,[484,5430,5431],{},"        '\u002F404': (_, __, ___) => const UnknownScreen(),\n",[484,5433,5435],{"class":486,"line":5434},123,[484,5436,4044],{},[484,5438,5440],{"class":486,"line":5439},124,[484,5441,2336],{},[484,5443,5445],{"class":486,"line":5444},125,[484,5446,5447],{},"    guards: [\n",[484,5449,5451],{"class":486,"line":5450},126,[484,5452,5453],{},"      BeamGuard(\n",[484,5455,5457],{"class":486,"line":5456},127,[484,5458,5459],{},"        pathPatterns: ['\u002Fcontact\u002F*'],\n",[484,5461,5463],{"class":486,"line":5462},128,[484,5464,5465],{},"        check: (_, beamLocation) {\n",[484,5467,5469],{"class":486,"line":5468},129,[484,5470,5471],{},"          final beamState = beamLocation.state as BeamState;\n",[484,5473,5475],{"class":486,"line":5474},130,[484,5476,5477],{},"          final idParameter = beamState.pathParameters['id'];\n",[484,5479,5481],{"class":486,"line":5480},131,[484,5482,5483],{},"          if (idParameter != null) {\n",[484,5485,5487],{"class":486,"line":5486},132,[484,5488,5489],{},"            final id = int.tryParse(idParameter);\n",[484,5491,5493],{"class":486,"line":5492},133,[484,5494,5495],{},"            if (id == null || id \u003C 0 || id >= contacts.length) {\n",[484,5497,5499],{"class":486,"line":5498},134,[484,5500,5501],{},"              return false;\n",[484,5503,5505],{"class":486,"line":5504},135,[484,5506,5507],{},"            }\n",[484,5509,5511],{"class":486,"line":5510},136,[484,5512,5513],{},"          }\n",[484,5515,5517],{"class":486,"line":5516},137,[484,5518,5519],{},"          return true;\n",[484,5521,5523],{"class":486,"line":5522},138,[484,5524,1688],{},[484,5526,5528],{"class":486,"line":5527},139,[484,5529,5530],{},"        beamToNamed: (_, __) => '\u002F404',\n",[484,5532,5534],{"class":486,"line":5533},140,[484,5535,5536],{},"      )\n",[484,5538,5540],{"class":486,"line":5539},141,[484,5541,5542],{},"    ],\n",[484,5544,5546],{"class":486,"line":5545},142,[484,5547,765],{},[484,5549,5551],{"class":486,"line":5550},143,[484,5552,5553],{},"  final _routeInformationParser = BeamerParser();\n",[484,5555,5557],{"class":486,"line":5556},144,[484,5558,503],{"emptyLinePlaceholder":502},[484,5560,5562],{"class":486,"line":5561},145,[484,5563,509],{},[484,5565,5567],{"class":486,"line":5566},146,[484,5568,515],{},[484,5570,5572],{"class":486,"line":5571},147,[484,5573,4658],{},[484,5575,5577],{"class":486,"line":5576},148,[484,5578,3069],{},[484,5580,5582],{"class":486,"line":5581},149,[484,5583,4667],{},[484,5585,5587],{"class":486,"line":5586},150,[484,5588,4672],{},[484,5590,5592],{"class":486,"line":5591},151,[484,5593,592],{},[484,5595,5597],{"class":486,"line":5596},152,[484,5598,598],{},[484,5600,5602],{"class":486,"line":5601},153,[484,5603,604],{},[132,5605,5606,5608,5609,361,5611,5613,5614,361,5616,5618,5619,5622,5623,5626,5627,4879],{},[111,5607,1110],{}," as in the Router API version, ",[139,5610,3451],{},[139,5612,3454],{}," have been removed; use ",[139,5615,3462],{},[139,5617,3468],{},". With Beamer 1.7.0 the rest compiles as printed; the runnable copy only adds ",[139,5620,5621],{},".call"," after ",[139,5624,5625],{},"RoutesLocationBuilder(...)",", because the analyzer flags passing a callable object where a function is expected (lint ",[139,5628,5629],{},"implicit_call_tearoffs",[120,5631,5632,341,5634,5637,5638,5640],{},[228,5633,804],{},[139,5635,5636],{},"examples\u002Fflutter_for_jobseekers_ch08\u002Flib\u002Fbeamer\u002Fmain.dart"," (uses the shared screens in ",[139,5639,3498],{},")",[276,5642,5643,5644,5647,5648,393],{},"As you can see, the same application using Beamer simultaneously harnesses the ",[111,5645,5646],{},"power of the Router API"," while delivering something nearing the ",[111,5649,5650],{},"simplicity of Navigator 1.0",[132,5652,5653,5656,5657,5660,5661,5664],{},[228,5654,5655],{},"(added, not in the book)"," The Flutter documentation now names ",[111,5658,5659],{},"go_router"," as its example of a routing package: \"Flutter applications with advanced navigation and routing requirements (such as a web app that uses direct links to each screen, or an app with multiple Navigator widgets) should use a routing package such as go_router that can parse the route path and configure the Navigator whenever the app receives a new deep link\" (Flutter, n.d.-a). go_router is published on pub.dev by the verified publisher ",[139,5662,5663],{},"flutter.dev"," (pub.dev, n.d.). Beamer still works with current Flutter, but its latest release, 1.7.0, dates from October 2024.",[166,5666,5668],{"id":5667},"conclusion","Conclusion",[120,5670,5671],{},"Navigation and routing are ubiquitous in just about any application you will end up building. Having a firm understanding of how these systems work in Flutter is key to building any application which has more than a single screen (which will be most, if not all, of them!)",[120,5673,5674],{},"In the upcoming chapter, we will be looking at state management and the BLoC pattern (a commonly used state management system.) These systems will open a lot of new possibilities for us to build dynamic and complex experiences. So, refill your water, do some stretches, and when you are ready, let us dive into state management!",[166,5676,5678],{"id":5677},"questions","Questions",[5680,5681,5682,5685,5688,5691,5694,5697,5700,5703,5710,5719,5724,5730,5733,5736,5745,5750],"ol",{},[182,5683,5684],{},"The concept of sending a user from one screen to another is known as what?",[182,5686,5687],{},"What is the difference between navigation and routing?",[182,5689,5690],{},"When navigating between screens in Flutter, what analogy is useful in visualizing how different screens and their states are maintained?",[182,5692,5693],{},"What is the difference between imperative and declarative routing?",[182,5695,5696],{},"What widget is used to route imperatively in Flutter? What widget is used to route declaratively?",[182,5698,5699],{},"What are some of the limitations of Navigator 1.0?",[182,5701,5702],{},"How do you configure named routes, then navigate to a route by name?",[182,5704,5705,5706,361,5708,4862],{},"What's the difference between ",[139,5707,854],{},[139,5709,1138],{},[182,5711,5712,5713,5715,5716,5718],{},"What happens if you use ",[139,5714,1138],{}," followed by ",[139,5717,1120],{}," on the new screen?",[182,5720,5721,5722,4862],{},"How do you pass data to a new route? How do you get a value back when calling ",[139,5723,1120],{},[182,5725,5726,5727,5729],{},"What useful things can you use ",[139,5728,1251],{}," for?",[182,5731,5732],{},"What widget can be used to animate a widget from one screen to another?",[182,5734,5735],{},"What is the correct name for Navigator 2.0?",[182,5737,5738,5739,5741,5742,5744],{},"How are the ",[139,5740,3504],{}," widget and ",[139,5743,3508],{}," method used?",[182,5746,5747,5748,4862],{},"What is a ",[139,5749,3478],{},[182,5751,5752],{},"How do you change the transition animation when navigating to a new route using the Router API?",[166,5754,5756],{"id":5755},"key-terms","Key terms",[3556,5758,5759,5763,5767],{},[3559,5760,5762],{"name":5761},"Declarative programming","Code that provides a description of the expected outcome but not instructions to accomplish it.",[3559,5764,5766],{"name":5765},"Imperative programming","Code that has step-by-step instructions to complete the task at hand.",[3559,5768,5770],{"name":5769},"Intent","The expected outcome of a user's action.",[166,5772,2873],{"id":5773},"further-reading",[171,5775,5776,5783,5792,5797],{},[174,5777,5782],{"icon":5778,"title":5779,"target":5780,"to":5781},"i-simple-icons-flutter","Animations in Flutter","_blank","https:\u002F\u002Fdocs.flutter.dev\u002Fui\u002Fanimations","Flutter's documentation on animating widgets.",[174,5784,5787,5788,393],{"icon":6,"title":5785,"target":5780,"to":5786},"All about Beamer","https:\u002F\u002Fbeamer.dev\u002F","The Beamer website; the package is at ",[148,5789,5790],{"href":5790,"rel":5791},"https:\u002F\u002Fpub.dev\u002Fpackages\u002Fbeamer",[152],[174,5793,5796],{"icon":5794,"title":5795,"target":5780,"to":2935},"i-simple-icons-medium","Learning Navigator 2.0 (the Router API)","An article on the Router API in the Flutter publication on Medium, the source of Figure 8.1.",[174,5798,5802],{"icon":5799,"title":5800,"target":5780,"to":5801},"i-simple-icons-dart","go_router (added, not in the book)","https:\u002F\u002Fpub.dev\u002Fpackages\u002Fgo_router","The routing package named in Flutter's navigation documentation.",[132,5804,5805,5807,5808,5812,5813,5816],{},[111,5806,1110],{}," the book's animations link, ",[148,5809,5810],{"href":5810,"rel":5811},"https:\u002F\u002Fdocs.flutter.dev\u002Fdevelopment\u002Fui\u002Fanimations",[152],", now redirects to ",[148,5814,5781],{"href":5781,"rel":5815},[152]," (Flutter, n.d.-e).",[166,5818,5820],{"id":5819},"references","References",[179,5822,5823,5835,5848,5861,5873,5885,5896,5912],{},[182,5824,5825,5826,5828,5829,341,5833],{},"BPB Publications. (n.d.). ",[228,5827,17],{}," (companion code repository). Retrieved from GitHub: ",[148,5830,5831],{"href":5831,"rel":5832},"https:\u002F\u002Fgithub.com\u002Fbpbpublications\u002FFlutter-for-Jobseekers",[152],[228,5834,5655],{},[182,5836,5837,5838,5841,5842,341,5846],{},"Flutter. (n.d.-a). ",[228,5839,5840],{},"Navigation and routing",". Retrieved from Flutter: ",[148,5843,5844],{"href":5844,"rel":5845},"https:\u002F\u002Fdocs.flutter.dev\u002Fui\u002Fnavigation",[152],[228,5847,5655],{},[182,5849,5850,5851,5854,5855,341,5859],{},"Flutter. (n.d.-b). ",[228,5852,5853],{},"onPopPage property",". Retrieved from Flutter API: ",[148,5856,5857],{"href":5857,"rel":5858},"https:\u002F\u002Fapi.flutter.dev\u002Fflutter\u002Fwidgets\u002FNavigator\u002FonPopPage.html",[152],[228,5860,5655],{},[182,5862,5863,5864,5854,5867,341,5871],{},"Flutter. (n.d.-c). ",[228,5865,5866],{},"location property",[148,5868,5869],{"href":5869,"rel":5870},"https:\u002F\u002Fapi.flutter.dev\u002Fflutter\u002Fwidgets\u002FRouteInformation\u002Flocation.html",[152],[228,5872,5655],{},[182,5874,5875,5876,5854,5879,341,5883],{},"Flutter. (n.d.-d). ",[228,5877,5878],{},"ValueChanged typedef",[148,5880,5881],{"href":5881,"rel":5882},"https:\u002F\u002Fapi.flutter.dev\u002Fflutter\u002Ffoundation\u002FValueChanged.html",[152],[228,5884,5655],{},[182,5886,5887,5888,5841,5891,341,5894],{},"Flutter. (n.d.-e). ",[228,5889,5890],{},"Introduction to animations",[148,5892,5781],{"href":5781,"rel":5893},[152],[228,5895,5655],{},[182,5897,5898,5899,5905,5906,341,5910],{},"flutter\u002Fflutter. (n.d.). ",[228,5900,5901,5902,5904],{},"Remove deprecated ",[139,5903,3458],{}," members (#139255)",". Retrieved from GitHub: ",[148,5907,5908],{"href":5908,"rel":5909},"https:\u002F\u002Fgithub.com\u002Fflutter\u002Fflutter\u002Fpull\u002F139255",[152],[228,5911,5655],{},[182,5913,5914,5915,5917,5918,341,5921],{},"pub.dev. (n.d.). ",[228,5916,5659],{},". Retrieved from pub.dev: ",[148,5919,5801],{"href":5801,"rel":5920},[152],[228,5922,5655],{},[5924,5925,5926],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":106,"searchDepth":493,"depth":493,"links":5928},[5929,5930,5934,5938,5943,5950,5955,5956,5969,5970,5971,5972,5973,5974],{"id":168,"depth":493,"text":169},{"id":222,"depth":493,"text":223,"children":5931},[5932,5933],{"id":245,"depth":499,"text":246},{"id":285,"depth":499,"text":286},{"id":354,"depth":493,"text":355,"children":5935},[5936,5937],{"id":407,"depth":499,"text":408},{"id":462,"depth":499,"text":463},{"id":845,"depth":493,"text":190,"children":5939},[5940,5941,5942],{"id":929,"depth":499,"text":930},{"id":1032,"depth":499,"text":1033},{"id":1145,"depth":499,"text":1146},{"id":1228,"depth":493,"text":193,"children":5944},[5945,5946,5948],{"id":1261,"depth":499,"text":1262},{"id":1409,"depth":499,"text":5947},"Reading the arguments with ModalRoute.of",{"id":1609,"depth":499,"text":5949},"Using onGenerateRoute",{"id":2004,"depth":493,"text":196,"children":5951},[5952,5953,5954],{"id":2025,"depth":499,"text":2026},{"id":2253,"depth":499,"text":2254},{"id":2296,"depth":499,"text":2297},{"id":2497,"depth":493,"text":199},{"id":2877,"depth":493,"text":202,"children":5957},[5958,5959,5960,5961,5963,5965,5967,5968],{"id":2939,"depth":499,"text":2940},{"id":2967,"depth":499,"text":2968},{"id":3544,"depth":499,"text":3545},{"id":3645,"depth":499,"text":5962},"The RoutePath",{"id":3771,"depth":499,"text":5964},"The RouterDelegate",{"id":4364,"depth":499,"text":5966},"The RouteInformationParser",{"id":4608,"depth":499,"text":4609},{"id":4690,"depth":499,"text":4691},{"id":4868,"depth":493,"text":205},{"id":5667,"depth":493,"text":5668},{"id":5677,"depth":493,"text":5678},{"id":5755,"depth":493,"text":5756},{"id":5773,"depth":493,"text":2873},{"id":5819,"depth":493,"text":5820},"Navigator 1.0 (push and pop, named routes, route arguments, returning data, Hero animations), the Router API (Navigator 2.0), and routing with Beamer.","md",null,{},{"icon":61},{"title":58,"description":5975},"IeTOfFNIiLInd3Z6pq0PsWie9K6yknFd-D3zkCcyV1c",[5983,5985],{"title":53,"path":54,"stem":55,"description":5984,"icon":56,"children":-1},"Futures and async\u002Fawait, requesting and sending data with the http package, turning JSON into Dart classes, FutureBuilder and StreamBuilder, and sinks and streams.",{"title":63,"path":64,"stem":65,"description":5986,"icon":66,"children":-1},"Ephemeral versus app state, and one shopping cart built four ways — with an inherited widget, Provider, Cubit and BLoC.",1795696849931]