text stringlengths 1 474 |
|---|
<topic_start>Navigation and routing |
Flutter provides a complete system for navigating between screens and handling |
deep links. Small applications without complex deep linking can use |
Navigator, while apps with specific deep linking and navigation |
requirements should also use the Router to correctly handle deep links on |
Android and iOS, and to stay in sync with the address bar when the app is |
running on the web.To configure your Android or iOS application to handle deep links, see |
Deep linking.<topic_end> |
<topic_start> |
Using the Navigator |
The Navigator widget displays screens as a stack using the correct transition |
animations for the target platform. To navigate to a new screen, access the |
Navigator through the route’s BuildContext and call imperative methods such |
as push() or pop():Because Navigator keeps a stack of Route objects (representing the history |
stack), The push() method also takes a Route object. The MaterialPageRoute |
object is a subclass of Route that specifies the transition animations for |
Material Design. For more examples of how to use the Navigator, follow the |
navigation recipes from the Flutter Cookbook or visit the Navigator API |
documentation.<topic_end> |
<topic_start> |
Using named routes |
info Note |
We don’t recommend using named routes for most applications. |
For more information, see the Limitations section below.Applications with simple navigation and deep linking requirements can use the |
Navigator for navigation and the MaterialApp.routes parameter for deep |
links:Routes specified here are called named routes. For a complete example, follow |
the Navigate with named routes recipe from the Flutter Cookbook.<topic_end> |
<topic_start> |
Limitations |
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 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.<topic_end> |
<topic_start> |
Using the Router |
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.To use the Router, switch to the router constructor on MaterialApp or |
CupertinoApp and provide it with a Router configuration. Routing packages, |
such as go_router, typically provide a |
configuration for you. For example:Because packages like go_router are declarative, they will always display the |
same screen(s) when a deep link is received.Note for advanced developers: If you prefer not to use a routing package |
and would like full control over navigation and routing in your app, override |
RouteInformationParser and RouterDelegate. When the state in your app |
changes, you can precisely control the stack of screens by providing a list of |
Page objects using the Navigator.pages parameter. For more details, see the |
Router API documentation.<topic_end> |
<topic_start> |
Using Router and Navigator together |
The Router and Navigator are designed to work together. You can navigate |
using the Router API through a declarative routing package, such as |
go_router, or by calling imperative methods such as push() and pop() on |
the Navigator.When you navigate using the Router or a declarative routing package, each |
route on the Navigator is page-backed, meaning it was created from a |
Page using the pages |
argument on the Navigator constructor. Conversely, any Route |
created by calling Navigator.push or showDialog will add a pageless |
route to the Navigator. If you are using a routing package, Routes that are |
page-backed are always deep-linkable, whereas pageless routes |
are not.When a page-backed Route is removed from the Navigator, all of the |
pageless routes after it are also removed. For example, if a deep link |
navigates by removing a page-backed route from the Navigator, all pageless |
_routes after (up until the next _page-backed route) are removed too.info Note |
You can’t prevent navigation from page-backed screens using WillPopScope. |
Instead, you should consult your routing package’s API documentation.<topic_end> |
<topic_start> |
Web support |
Apps using the Router class integrate with the browser History API to provide |
a consistent experience when using the browser’s back and forward buttons. |
Whenever you navigate using the Router, a History API entry is added to the |
browser’s history stack. Pressing the back button uses reverse |
chronological navigation, meaning that the user is taken to the previously |
visited location that was shown using the Router. This means that if the user |
pops a page from the Navigator and then presses the browser back button |
the previous page is pushed back onto the stack.<topic_end> |
<topic_start> |
More information |
For more information on navigation and routing, check out the following |
resources: |
<topic_end> |
<topic_start>Work with tabs |
Working with tabs is a common pattern in apps that follow the |
Material Design guidelines. |
Flutter includes a convenient way to create tab layouts as part of |
the material library.This recipe creates a tabbed example using the following steps;<topic_end> |
<topic_start> |
1. Create a TabController |
For tabs to work, you need to keep the selected tab and content |
sections in sync. |
This is the job of the TabController.Either create a TabController manually, |
or automatically by using a DefaultTabController widget.Using DefaultTabController is the simplest option, since it |
creates a TabController and makes it available to all descendant widgets. |
<code_start>return MaterialApp( |
home: DefaultTabController( |
length: 3, |
child: Scaffold(), |
), |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.