<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by AybukeYaman on Medium]]></title>
        <description><![CDATA[Stories by AybukeYaman on Medium]]></description>
        <link>https://medium.com/@aybukeyaman5806?source=rss-18d979b3fd8f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lwIcNmM7KZyol3xS</url>
            <title>Stories by AybukeYaman on Medium</title>
            <link>https://medium.com/@aybukeyaman5806?source=rss-18d979b3fd8f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 07:02:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aybukeyaman5806/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Flutter Navigation Made Easy]]></title>
            <link>https://medium.com/@aybukeyaman5806/flutter-navigation-made-easy-7af267cb71b9?source=rss-18d979b3fd8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7af267cb71b9</guid>
            <category><![CDATA[navigation]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[stack]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[AybukeYaman]]></dc:creator>
            <pubDate>Sat, 07 Mar 2026 18:23:45 GMT</pubDate>
            <atom:updated>2026-03-07T18:24:49.750Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Learn How to Handle Page Transitions and Data Passing</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WgRkNnYJPIZ_oA9H-oDQEQ.png" /></figure><p><strong>Understanding the Logic: The Stack Concept</strong></p><p>Before we start coding, we should understand the main logic behind the page transitions and how Flutter handles the situation.</p><p>First, remember that each algorithm and architecture starts with <strong>ANALOGY</strong> to make the code structure more understandable. Think of your app’s navigation like a <strong>stack of papers</strong> on the desk. When moving between screens, the logic is identical to this real-world analogy. When you want to add a new object to the <strong>Stack </strong>and remove the object from the <strong>Stack</strong>, we use two main functions:</p><ul><li><strong>Push(): </strong>To add a new screen <strong><em>(object)</em></strong> to the top of the stack.</li><li><strong>Pop(): </strong>To remove the top screen from the stack.</li></ul><p>This is the LIFO Structure, which can be described as Last in-First out.</p><p>Here is the visualized logic of the Stack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sbSpgVHkTgbmm5EPHxWJsg.png" /><figcaption>In Flutter, this “desk” is called the <strong>Navigator</strong>, and each “paper” is a <strong>Route.</strong></figcaption></figure><h3>Navigation Methods in Flutter</h3><p>Flutter provides different ways to handle navigation, depending on the complexity of your app. We can categorize them into three main methods:</p><h3>1. Basic Navigation (Navigator 1.0):</h3><p>The simplest way<strong> </strong>using <strong>push() </strong>and<strong> pop()</strong>. Those methods allow you to give direct command which makes them <strong>imperative. </strong>It is perfect for small or medium-sized apps.</p><p>In this method, we move directly to the next screen. Think of it like a <strong>“Go to” </strong>command. We usually trigger this inside a button’s <strong><em>onPressed</em></strong> property.</p><pre>// Inside your FirstScreen Widget</pre><pre>ElevatedButton(<br>  onPressed: () {<br>    // We use Navigator.push to go to the SecondScreen<br>    Navigator.push(<br>      context,<br>      MaterialPageRoute(builder: (context) =&gt; const SecondScreen()),<br>    );<br>  },<br>  child: const Text(&#39;Go to Second Screen&#39;),<br>)</pre><p><strong><em>MaterialPageRoute</em></strong> is a special class in Flutter that handles the transition animation. On <strong>Android</strong>, the new screen slides up; on <strong>iOS</strong>, it slides from the right. It makes your app feel “native.”</p><p>When you are on the <strong>second screen</strong>, you need a way to <strong>go back </strong>to the <strong><em>“bottom”</em></strong> of the stack.</p><pre>// Inside your SecondScreen Widget</pre><pre>ElevatedButton(<br>  onPressed: () {<br>    // This removes the top screen from the Stack<br>    Navigator.pop(context);<br>  },<br>  child: const Text(&#39;Go Back!&#39;),<br>)</pre><h4>1.1 Passing Data with Basic Navigation</h4><p>You can also pass data directly through the constructor:</p><pre>Navigator.push(<br>  context,<br>  MaterialPageRoute(<br>    builder: (context) =&gt; SecondScreen(userName: &#39;Buke&#39;),<br>  ),<br>);</pre><h4>1.2 Returning Data with Pop()</h4><p>Sometimes, you need to get data back from a screen. For example, a user fills a form, and you want that result. Here is how:</p><pre>// On the first screen: push and WAIT for a result<br>final result = await Navigator.push(<br>  context,<br>  MaterialPageRoute(builder: (context) =&gt; FormScreen()),<br>);<br>print(result); // &quot;User selected: Option A&quot;</pre><pre>// On the second screen: pop WITH data<br>Navigator.pop(context, &#39;User selected: Option A&#39;);</pre><p>The <strong><em>“await” </em></strong>keyword makes the first screen wait until the second screen pops with a value.</p><h4>1.3 Other Useful Methods</h4><p>Sometimes, <strong>push() </strong>and<strong> pop() </strong>are not enough. Here are two methods you will use often:</p><ul><li><strong>pushReplacement(): </strong>This replaces the current screen instead of adding a new one. Perfect for login screens, after the user logs in, you don’t want them to go <strong><em>“back” </em></strong>to the login page.</li></ul><pre>Navigator.pushReplacement(<br>  context,<br>  MaterialPageRoute(builder: (context) =&gt; const HomeScreen()),<br>);</pre><ul><li><strong>pushAndRemoveUntil(): </strong>This removes all previous screens from the stack. Use it when you want a<strong><em>“fresh start”, </em></strong>like after a logout.</li></ul><pre>Navigator.pushAndRemoveUntil(<br>  context,<br>  MaterialPageRoute(builder: (context) =&gt; const LoginScreen()),<br>  (route) =&gt; false, // This removes everything<br>);</pre><h3>2. Named Routes :</h3><p>As your app grows, writing with <strong>MaterialPageRoute </strong>everywhere becomes messy. Instead, we define all our <strong><em>“addresses”</em></strong> in one place (inside the <strong>MaterialApp</strong>) and use names. It makes the code much more organized.</p><h4>2.1 Step 1: Define the Routes</h4><pre>MaterialApp(<br>  // Initial route is the first screen (Home)<br>  initialRoute: &#39;/&#39;,<br>  routes: {<br>    &#39;/&#39;: (context) =&gt; const HomeScreen(),<br>    &#39;/details&#39;: (context) =&gt; const DetailScreen(),<br>  },<br>)</pre><h4>2.2 Step 2: Navigate by Name</h4><pre>// Now, navigation is much cleaner!</pre><pre>ElevatedButton(<br>  onPressed: () {<br>    Navigator.pushNamed(context, &#39;/details&#39;);<br>  },<br>  child: const Text(&#39;View Details&#39;),<br>)</pre><h4>2.3 How to Pass Data?</h4><ul><li>With named routes, you can use the <strong><em>“arguments” </em></strong>parameter to send data:</li></ul><pre>Navigator.pushNamed(context, &#39;/details&#39;, arguments: &#39;Hello &lt;3&#39;);</pre><h4>2.4 Receiving the Data</h4><ul><li>On the other screen, you need to <strong><em>“catch” </em></strong>this data.</li></ul><pre>// Inside DetailScreen&#39;s build method</pre><pre>@override<br>Widget build(BuildContext context) {</pre><pre>  // Extract the arguments from the route<br>  final message = ModalRoute.of(context)!.settings.arguments as String;</pre><pre>  return Scaffold(<br>    body: Center(<br>      child: Text(message), // This will display &quot;Hello &lt;3&quot;<br>    ),<br>  );<br>}</pre><ul><li><em>Note that using named routes is like using a GPS. You don’t need to know the details of the road (the code); you just need the name of the destination.</em></li></ul><h3>3. Advanced Navigation (Navigator 2.0 / Router API):</h3><p>While Navigator 1.0 is great, it was imperative. However, Navigator 2.0 is <strong>declarative, </strong>which means the navigation changes automatically based on the <strong>state </strong>of your app.</p><h4>3.1 When Should You Use It?</h4><ul><li><strong>Deep Linking: </strong>Imagine a user clicks on a link in a <strong>browser or message </strong>(like <strong><em>myapp.com/products/123</em></strong>). You want your app to open and jump directly to that specific product page. Navigator 2.0 handles this perfectly.</li><li><strong>Flutter Web: </strong>If you are building a website with Flutter, you need the browser’s “Back” and “Forward” buttons to work smoothly with your app’s screens.</li><li><strong>The Secret Weapon (<em>go_router</em>): </strong>Writing Navigator 2.0 from scratch requires a lot of complex code. Because of this, the official Flutter team highly recommends using a package called <strong>(<em>go_router</em>)</strong>. It does all the heavy lifting for you!</li></ul><p><strong>3.2 </strong>How to Use <strong>(<em>go_router</em>):</strong></p><p>Here is how simple it looks with <strong>(<em>go_router</em>)</strong></p><pre>// 1. Define your routes and handle dynamic data (like an ID)</pre><pre>final GoRouter _router = GoRouter(<br>  routes: [<br>    GoRoute(<br>      path: &#39;/&#39;,<br>      builder: (context, state) =&gt; const HomeScreen(),<br>    ),</pre><pre>    GoRoute(<br>      // The &#39;:id&#39; is a dynamic path parameter!<br>      path: &#39;/details/:id&#39;,<br>      builder: (context, state) {</pre><pre>        // Extract the ID from the path parameters<br>        final detailId = state.pathParameters[&#39;id&#39;];<br>        return DetailScreen(id: detailId);<br>      },<br>    ),<br>  ],<br>);<br></pre><pre>// 2. Tell your app to use this router</pre><pre>MaterialApp.router(<br>  routerConfig: _router,<br>);</pre><p>To move to the details page, you just say:</p><pre>// Navigating and passing data in one clean line:<br>context.go(&#39;/details/42&#39;);</pre><p><strong>3.3 Going back with (<em>go_router</em>):</strong></p><p>Just like basic navigation, you can also go back.</p><pre>context.pop();</pre><p>Simple as that!</p><h3>Conclusion</h3><p>Routing in Flutter might seem complex at first, but don’t worry. It is easy to understand with the “Stack logic”. For small projects, basic push and pop methods are enough. As your app grows, Named Routes will help you to organize your code.</p><p>Finally, for modern and complex apps, learning declarative navigation with go_router is the best choice.</p><p>💖Happy Coding💖</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7af267cb71b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>