owen-yap / Cyberlife

Orthopedics app for assisting in pre-consultation medical examinations, developed with NUH
1 stars 0 forks source link

Implement Routes in main app #20

Open praveenkrishna0512 opened 1 year ago

praveenkrishna0512 commented 1 year ago

Using routes in Flutter offers several advantages over directly using Navigator.push in the onPressed callback.

Thus, it would be good practice to eventually implement them.

praveenkrishna0512 commented 1 year ago

Listed below are some reason for the above.

  1. Organization and Separation of Concerns: Defining routes in your MaterialApp allows you to separate the routing logic from the UI components. It keeps your codebase more organized and makes it easier to manage navigation throughout the app.

  2. Declarative and Centralized Configuration: By defining routes in your MaterialApp, you provide a centralized and declarative way of specifying the available routes in your app. It allows you to easily view and understand the navigation structure of your app.

  3. Named Routes: With named routes, you can refer to routes by their names instead of specifying the actual widget or screen directly. This improves readability and maintainability, especially in larger apps with complex navigation flows.

  4. Automatic Route Transitions: By defining routes, you can specify default transition animations for route changes, such as slide transitions, fade transitions, or custom transitions. This simplifies the process of adding consistent and polished animations to your app.

  5. Navigation Stack Management: Routes in Flutter maintain a navigation stack, allowing users to navigate back and forth between screens using the system back button or gestures. This behavior is handled automatically by Flutter when using routes, whereas manual stack management is required when using Navigator.push directly.

  6. Route Management and Deep Linking: Using named routes enables easier management of deep links and handling dynamic route parameters. It allows you to parse route parameters automatically and pass them to the destination screen without complex manual parsing.