Recognized by Clutch.co as a top-rated Mobile App Development Company.
folio3-mobile
US 408 365 4638
START YOUR PROJECT
  • Solutions
    • Apps Discovery Services
    • Team Augmentation
    • Enterprise
    • AR/VR
    • IoT
    • Wearables
    • Field Sales
    • On Demand Apps
  • Industries
    • Retail
    • Agriculture
    • Healthcare
    • Pharmaceutical & Life Sciences
    • Manufacturing
    • Automotive
    • Logistics
    • Education
  • Technologies
    • Native Mobile Apps
      • iOS
      • Android
    • Cross Platform Apps
      • React Native
      • Flutter
      • Ionic
      • Xamarin
      • NativeScript
      • Sencha
  • Portfolio
  • Blog
  • Contact Us
  • Solutions
    • Apps Discovery Services
    • Team Augmentation
    • Enterprise
    • AR/VR
    • IoT
    • Wearables
    • Field Sales
    • On Demand Apps
  • Industries
    • Retail
    • Agriculture
    • Healthcare
    • Pharmaceutical & Life Sciences
    • Manufacturing
    • Automotive
    • Logistics
    • Education
  • Technologies
    • Native Mobile Apps
      • iOS
      • Android
    • Cross Platform Apps
      • React Native
      • Flutter
      • Ionic
      • Xamarin
      • NativeScript
      • Sencha
  • Portfolio
  • Blog
  • Contact Us

Exploring Flutter Navigation: From Basics to Advanced Routes

Published by: Muhammad Saeed Younus | December 6, 2023 msaqlain
SCROLL AND BE AMAZED!
Home > App Development • flutter-app-development > Exploring Flutter Navigation: From Basics to Advanced Routes

Hello, everyone! It’s been a while since we last caught up 😄. Today, I’m excited to share an effective method for creating routes in the go_router library and explore the advanced features of ShellRoutes to take your Flutter navigation to the next level.

Understanding the Root and Nested Routes 🌲

Let’s begin by addressing a common issue in go_router usage. While it seamlessly handles smaller applications, certain use cases can be problematic if not handled correctly. Placing all routes at the root level can lead to unexpected behaviors.

// Example with routes at the root level
return MaterialApp.router(
 // ... other configurations
 routerConfig: GoRouter(
   initialLocation: '/splash',
   routes: [
     // ... routes
   ],
 ),
);

Understanding the concepts of root and nested routes is crucial. A root route closes the application when the back button is pressed, while a nested route does not.

Refactoring Routes for Better Structure 🏗️

To address this, consider restructuring your routes. In the refactored example below, routes are organized into root and nested categories, creating a more structured approach:

// Refactored example with root and nested routes
return MaterialApp.router(
 // ... other configurations
 routerConfig: GoRouter(
   initialLocation: '/splash',
   routes: [
     GoRoute(
       name: 'splash',
       path: '/splash',
       builder: (context, state) => const SplashScreen(),
     ),
     GoRoute(
       name: 'getStarted',
       path: '/getStarted',
       builder: (context, state) => const GetStartedScreen(),
       routes: [
         // ... nested routes
       ],
     ),
     // ... other routes
   ],
 ),
);

This structure allows for a more controlled navigation experience, particularly when using the goNamed method. Nested routes automatically generate and maintain the back stack, ensuring a smoother user experience.

Exploring Advanced Navigation with ShellRoutes 🐚

As we delve deeper into the capabilities of go_router, it’s essential to explore advanced features like ShellRoutes. ShellRoutes provides a powerful mechanism for managing complex navigation flows in your Flutter application.

What are ShellRoutes?

ShellRoutes allows you to create a hierarchical structure for your routes, similar to nested routes, but with added flexibility. They act as shells that encapsulate specific sections of your application, providing a more modular and maintainable approach.

Implementing ShellRoutes

To implement ShellRoutes, you can leverage the ShellRouter class within the go_router library. Let’s take a look at a basic example:

return MaterialApp.router( // ... other configurations
 routerConfig: GoRouter(
   initialLocation: '/shellHome',
   routes: [
     ShellRoute(
       name: 'shellHome',
       builder: (context, state, child) => const ShellHomeScreen(),
       routes: [
         GoRoute(
           name: 'dashboard',
           path: '/dashboard',
           builder: (context, state) => const DashboardScreen(),
         ),
         GoRoute(
           name: 'notifications',
           path: '/notifications',
           builder: (context, state) => const NotificationsScreen(),
         ),
       ],
     ), // ... other routes
   ],
 ),
);

In this example, ShellHomeScreen serves as the shell, containing nested routes for the dashboard and notifications. The use of ShellRoutes enhances code organization and navigation management.

Unleashing the Power of ShellRoutes

ShellRoutes offers a dynamic and modular approach to Flutter application navigation. Let’s delve into the compelling benefits that come with embracing this advanced feature.

Benefits of ShellRoutes

  • Modularity: ShellRoutes enables you to compartmentalize different sections of your app, promoting a modular code structure.
  • Code Reusability: By encapsulating specific functionalities within shells, you can easily reuse them across different parts of your application.
  • Effortless Maintenance: Managing and updating specific sections of your app becomes more straightforward with the structured approach offered by ShellRoutes.

Going Beyond Basics

Feel free to experiment with more advanced features of ShellRoutes, such as route guards, transitions, and customizations. The flexibility provided by ShellRoutes empowers you to create a navigation architecture tailored to your application’s unique requirements.

In the next part of this article series, we’ll explore these advanced ShellRoutes features in detail, unlocking the full potential of go_router for your Flutter development.

To sum it up, navigating Flutter development complexities becomes more straightforward with the structured approach of go_router and embracing nested routes, including advanced features like ShellRoutes. This ensures scalability and efficient navigation, making it a valuable tool for maintainable code.

Feel free to explore further, and thank you for taking the time to read this comprehensive article! Happy coding and fluttering! 😁✨🚀Here is the code for go_router best practices
https://github.com/saeed-younus/flutter_best_practices


About Muhammad Saeed Younus

Newsletter

Search

Archives

  • December 2023
  • April 2023
  • March 2023
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • October 2021
  • September 2021
  • May 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • May 2019

Recent Posts

  • Exploring Flutter Navigation: From Basics to Advanced Routes
  • Web UI Test Automation with Pytest-BDD
  • How to fix IOS compass calibration issues
  • Testing Android Applications With Perfect Coverage
  • How to use useRef hook efficiently? – React

Tags

  • android
  • angular-state-management
  • Automation
  • Compass
  • cross-platform
  • css
  • development
  • firebase
  • hooks
  • ios
  • learn-ngrx
  • ngrx-beginner
  • ngrx/store
  • QA
  • react-native
  • reactjs
  • scss
  • stylesheet
  • styling
  • Testing
  • Test Script
  • UI-UX

Newsletter

Newsletter

Post navigation

Previous Web UI Test Automation with Pytest-BDD
Schedule an Appointment with our Mobile App Development Expert
Footer Menu
  • Company
    • About Us
    • Portfolio
    • Blog
    • Careers
    • Contact Us
  • Solutions
    • Apps Discovery Services
    • Team Augmentation
    • Enterprise App Development
    • AR/VR Application Development
    • IoT Application Development
    • Wearables Apps Development
    • Field Sales
    • On-Demand Apps Development
  • Technologies
    • iOS
    • Android
    • React Native
    • Flutter
    • Ionic
    • Xamarin
    • NativeScript
    • HTML5
    • Sencha
  • Industries
    • Retail
    • Agriculture
    • Healthcare
    • Pharmaceutical
    • Manufacturing
    • Automotive
    • Logistics
    • Education

US Office

Belmont, California – 1301 Shoreway Road, Suite 160, Belmont, CA 94002

Pleasanton, California – 6701 Koll Center Parkway, #250 Pleasanton, CA 94566

Tel: +1 408 365 4638
Support: +1 (408) 512 1812

Mexico Office

Amado Nervo #2200, Edificio Esfera 1 piso 4, Col. Jardines del Sol, CP. 45050, Zapopan, Jalisco, Mexico

Bulgaria Office

49 Bacho Kiro Street, Sofia, 1000, Bulgaria

Canada Office​

895 Don Mills Road, Two Morneau Shepell Centre, Suite 900, Toronto, Ontario, M3C 1W3, Canada

UK Office

Export House, Cawsey Way, Woking Surrey, GU21 6QX

Tel: +44 (0) 14 8361 6611

UAE Office

Dubai, UAE – Dubai Internet City, 1st Floor, Building Number 12, Premises ED 29, Dubai, UAE

Tel: +971-55-6540154
Tel: +971-04-2505173

Pakistan Office

Folio3 Tower, Plot 26, Block B, SMCH Society, Main Shahrah-e-Faisal, Karachi.

First Floor, Blue Mall 8-R, MM Alam Road Gulberg III, Lahore.

Tel: +92-21-3432 3721-4 

© 2025, Folio3 Software Inc., All rights reserved.

  • Privacy policy and terms of use
  • Cookie Policy
Follow us on
Facebook-f Linkedin-in Instagram

Get a free app audit

[contact-form-7 id="3548" title="Float Banner Form"]