I want to access page view
as well as the bottom navigator
with the same controller so that I can have that page swipe action that page view has by default.
I wanted to link pageview screens to the bottom navigator with the controller to have a swipe page change action. Now I do have to use page view with bottom navigator, but which is linked together with the current index number due to which page swipe transitions fail to execute. now the page changes only when I click the specific page on the bottom navigator.
and i need to reduce the api calling too..
i am using AutomaticKeepAliveClientMixin as of now
Is there any other way I can get the page swipe transition to sync with the bottom navigator Which can also reduce the api calling??
Code
Scaffold part
Scaffold(
appBar: ToolbarNavigation(title, CustomColors.colorBlue),
body: PageView(
physics: const NeverScrollableScrollPhysics(),
controller: pageController,
onPageChanged: onPageChanged,
children: screens,
),
/* Bottom Navigator */
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
selectedItemColor: CustomColors.colorBlue,
type: BottomNavigationBarType.fixed,
iconSize: 30,
items: [
BottomNavigationBarItem(
icon: Image(
image: const AssetImage(Constants.Home),
height: 30,
width: 30,
),
label: 'Home',
tooltip: '',
),
BottomNavigationBarItem(
icon: const AssetImage(Constants. a),
height: 30,
width: 30,
),
label: 'A',
tooltip: '',
),
BottomNavigationBarItem(
icon: Image(
image: const AssetImage(Constants. b),
height: 30,
width: 30,
),
label: 'B',
tooltip: '',
),
BottomNavigationBarItem(
icon: Image(
image: const AssetImage(Constants.c),
height: 30,
width: 30,
),
label: 'C',
tooltip: '',
),
],
onTap: (index) {
onTabChange(index);
},
),
),
@override
void initState() {
screens = [
Home(),
const A(),
const B(),
const C(),
];
pageController = PageController(initialPage: widget.pageNumber);
_currentIndex = widget.pageNumber;
super.initState();
SchedulerBinding.instance.addPostFrameCallback((_) {
});
}
OnTabChange & OnPageChange
int _currentIndex = 0;
void onTabChange(index) {
setState(() {
_currentIndex = index;
});
pageController.jumpToPage(index);
}
void onPageChanged(int index) {
setState(() {
_currentIndex = index;
});
}
3
Answers
Use pageview in body and you got what you want
thanks
You can use
PageView
andBottomNavigationBar
together. I hope it’ll help you.Please try this and let me know if it meets your requirement
Solution 1
: Using Bottom Navigation BarSolution 2
: Without using Bottom Navigation Bar