text
stringlengths
1
372
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(),
),
);
<code_end>
<topic_end>
<topic_start>
2. create the tabs
when a tab is selected, it needs to display content.
you can create tabs using the TabBar widget.
in this example, create a TabBar with three
tab widgets and place it within an AppBar.
<code_start>
return MaterialApp(