text
stringlengths
1
474
}
}<code_end>
A TabController is required to coordinate the tab selection
between a TabBar and a TabBarView.
The TabController constructor length argument is the total
number of tabs. A TickerProvider is required to trigger
the notification whenever a frame triggers a state change.
The TickerProvider is vsync. Pass the
vsync: this argument to the TabController constructor
whenever you create a new TabController.The TickerProvider is an interface implemented
by classes that can vend Ticker objects.
Tickers can be used by any object that must be notified whenever a
frame triggers, but they’re most commonly used indirectly via an
AnimationController. AnimationControllers
need a TickerProvider to obtain their Ticker.
If you are creating an AnimationController from a State,
then you can use the TickerProviderStateMixin
or SingleTickerProviderStateMixin
classes to obtain a suitable TickerProvider.The Scaffold widget wraps a new TabBar widget and
creates two tabs. The TabBarView widget
is passed as the body parameter of the Scaffold widget.
All screens corresponding to the TabBar widget’s tabs are
children to the TabBarView widget along with the same TabController.
<code_start>class _NavigationHomePageState extends State<NavigationHomePage>
with SingleTickerProviderStateMixin {
late TabController controller = TabController(length: 2, vsync: this);
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: Material(
color: Colors.blue,
child: TabBar(
tabs: const <Tab>[
Tab(
icon: Icon(Icons.person),
),
Tab(
icon: Icon(Icons.email),
),
],
controller: controller,
),
),
body: TabBarView(
controller: controller,
children: const <Widget>[HomeScreen(), TabScreen()],
));
}
}<code_end>
<topic_end>
<topic_start>Drawer navigation
In React Native, import the needed react-navigation packages and then use
createDrawerNavigator and DrawerNavigation.In Flutter, we can use the Drawer widget in combination with a
Scaffold to create a layout with a Material Design drawer.
To add a Drawer to an app, wrap it in a Scaffold widget.
The Scaffold widget provides a consistent
visual structure to apps that follow the
Material Design guidelines. It also supports
special Material Design components,
such as Drawers, AppBars, and SnackBars.The Drawer widget is a Material Design panel that slides
in horizontally from the edge of a Scaffold to show navigation
links in an application. You can
provide a ElevatedButton, a Text widget,
or a list of items to display as the child to the Drawer widget.
In the following example, the ListTile
widget provides the navigation on tap.
<code_start>@override
Widget build(BuildContext context) {
return Drawer(
elevation: 20,
child: ListTile(
leading: const Icon(Icons.change_history),
title: const Text('Screen2'),
onTap: () {
Navigator.of(context).pushNamed('/b');
},
),
);
}<code_end>
The Scaffold widget also includes an AppBar widget that automatically
displays an appropriate IconButton to show the Drawer when a Drawer is
available in the Scaffold. The Scaffold automatically handles the
edge-swipe gesture to show the Drawer.
<code_start>@override
Widget build(BuildContext context) {
return Scaffold(
drawer: Drawer(
elevation: 20,
child: ListTile(
leading: const Icon(Icons.change_history),
title: const Text('Screen2'),
onTap: () {
Navigator.of(context).pushNamed('/b');
},
),
),
appBar: AppBar(title: const Text('Home')),
body: Container(),
);
}<code_end>