import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_app/config/index.dart'; import 'package:fancy_bottom_navigation/fancy_bottom_navigation.dart'; import 'package:flutter_app/view/page/home.dart'; import 'package:flutter_app/view/page/style.dart'; import 'package:flutter_app/view/page/like.dart'; import 'package:flutter_app/view/page/about.dart'; import 'package:flutter_app/view/page/login.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; class BottomNavigationWidget extends StatefulWidget { _BottomNavigationWidgetState createState() => _BottomNavigationWidgetState(); } class _BottomNavigationWidgetState extends State { int _currentIndex = 0; var _currentPage; final List tabBodies = [ Login(), Home(), Style(), Like(), About(), ]; @override void initState() { _currentPage = tabBodies[_currentIndex]; super.initState(); } @override Widget build(BuildContext context) { // 适配屏幕尺寸 ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context); return Scaffold( body: new IndexedStack( index: _currentIndex, children: tabBodies, ), bottomNavigationBar: FancyBottomNavigation( tabs: [ TabData(iconData: Icons.home, title: "首页"), TabData(iconData: Icons.view_module, title: "分类"), TabData(iconData: Icons.favorite, title: "喜欢"), TabData(iconData: Icons.pperson, title: "我的") ], onTabChangedListener: (position) { setState(() { _currentIndex = position; _currentPage = tabBodies[_currentIndex]; }); }, ), ); } Icon getTabIcon(int index) { if (index == _currentIndex) { return Config.tabSelectedImages[index]; } else { return Config.tabImages[index]; } } }