flutterBottomNavigationBar切换页⾯保持状态不变BottomNavigationBar+List<Widget>⽆法实现,BottomNavigationBar+PageView可以。写法如下:///BottomNavigationBar+PageView切换页⾯保持状态不变
class TabbarPage extends StatefulWidget {
const TabbarPage({Key? key}) : super(key: key);
@override
_TabbarPageState createState() => _TabbarPageState();
}
class _TabbarPageState extends State<TabbarPage> {
late int _currentIndex;
late List<Widget> _pages;
late PageController _controller;
List<BottomNavigationBarItem> getItems(){
return [
BottomNavigationBarItem(
icon: Image.ast(R.astsImgXingxing, width: 20, height: 20, color: ,),
activeIcon: Image.ast(R.astsImgXingxing, width: 20, height: 20, color: Colors.blue,),
label: 'tabbar1',
),
BottomNavigationBarItem(
icon: Image.ast(R.astsImgDun, width: 20, height: 20, color: ,),
辣椒的做法activeIcon: Image.ast(R.astsImgDun, width: 20, height: 20, color: Colors.blue,),
label: 'tabbar2',
)
,
BottomNavigationBarItem(
icon: Image.ast(R.astsImgTalk, width: 20, height: 20, color: ,),
activeIcon: Image.ast(R.astsImgTalk, width: 20, height: 20, color: Colors.blue,),
label: 'tabbar3',
),
中国初中生
牛黄解毒片副作用];
素饺子馅}
@override
void initState() {
// TODO: implement initState
鲢鱼的做法
super.initState();
_currentIndex = 0;
形容夏天的句子_pages = [
///widget
FultterStart1(),
FultterStart2(),
FultterStart3(),
];
拉米夫定片_controller = PageController(initialPage: 0);
}
@override
void dispo() {
// TODO: implement dispo
super.dispo();
_controller.dispo();
}
旅游资料void _onTap(int index){
_controller.jumpToPage(index);
}
void _onPageChange(int index){
if (index != _currentIndex) {
tState(() {
_currentIndex = index;
});
}