I have a TabBarView which contains a List of items, and I assign a Navigator.push method for each item. Currently this method will jump to a new page.
My question is , is it possible to navigate to the new page inside the body of the TabBarView? Which means I would like to navigate to another page while keeping all my top app bar and BottomNavigationBar on the screen.
Yes, you need to put your TabBarView
inside a TabController
:
import 'package:flutter/material.dart';
void main() {
runApp(TabBarDemo());
}
class TabBarDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
tabs: [
Tab(icon: Icon(Icons.directions_car)),
Tab(icon: Icon(Icons.directions_transit)),
Tab(icon: Icon(Icons.directions_bike)),
],
),
title: Text('Tabs Demo'),
),
body: TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_transit),
Icon(Icons.directions_bike),
],
),
),
),
);
}
}
Taken from https://flutter.io/docs/cookbook/design/tabs
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.