![enter image description here]()
The Complete Example
First make a class MyBottomBarDemo
class MyBottomBarDemo extends StatefulWidget {
@override
_MyBottomBarDemoState createState() => new _MyBottomBarDemoState();
}
class _MyBottomBarDemoState extends State<MyBottomBarDemo> {
int _pageIndex = 0;
PageController _pageController;
List<Widget> tabPages = [
Screen1(),
Screen2(),
];
@override
void initState(){
_pageController = PageController(initialPage: _pageIndex);
super.initState();
}
@override
void dispose() {
super.dispose();
_pageController.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Multi tab / page view", style: TextStyle(color: Colors.white)),
backgroundColor: Colors.deepPurple,
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _pageIndex,
onTap: onTabTapped,
backgroundColor: Colors.white,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem( icon: Icon(Icons.home), title: Text("Home")),
BottomNavigationBarItem(icon: Icon(Icons.mail), title: Text("Messages")),
],
),
body: PageView(
children: tabPages,
onPageChanged: onPageChanged,
controller: _pageController,
),
drawer: SlideDrawer(),
);
}
void onPageChanged(int page) {
setState(() {
this._pageIndex = page;
});
}
void onTabTapped(int index) {
this._pageController.animateToPage(index,duration: const Duration(milliseconds: 500),curve: Curves.easeInOut);
}
}
Then create a your pagers screens
class Screen1(), extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
color: Colors.yellow,
child: StreamBuilder(
stream: getHomeDataList(param).asStream(), // This is your function of get data from network
builder: (BuildContext context, AsyncSnapshot snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting: {
return LoadingIndicatorView();
}
case ConnectionState.active: {
break;
}
case ConnectionState.done: {
if (snapshot.hasData) {
if (snapshot.data != null) {
if (snapshot.data.length > 0) {
return Container(
color: offBlueColor,
child: Scrollbar(
child: ListView.builder(
key: PageStorageKey('homeList'),
padding: EdgeInsets.all(5),
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
return ListTile(
title: Text('Home Page index $index')
);;
}),
),
);
} else {
return Text("No data found");
}
} else {
// display error message data is null.
return Text("No data found");
}
} else if (snapshot.hasError) {
return Text(snapshot.error.toString());
} else {
return Text("Something went wrong");
}
break;
}
case ConnectionState.none:{
break;
}
}
return Container();
},
),
);
}
}