text stringlengths 1 372 |
|---|
when there is insufficient space to support tabs, drawers |
provide a good alternative. |
<topic_end> |
<topic_start> |
tab navigation |
in react native, createBottomTabNavigator |
and TabNavigation are used to |
show tabs and for tab navigation. |
flutter provides several specialized widgets for drawer and |
tab navigation: |
<code_start> |
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin { |
late TabController controller = TabController(length: 2, vsync: this); |
@override |
widget build(BuildContext context) { |
return TabBar( |
controller: controller, |
tabs: const <tab>[ |
tab(icon: Icon(Icons.person)), |
tab(icon: Icon(Icons.email)), |
], |
); |
} |
} |
<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( |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.