1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'home_page.dart';
  4. import 'Information_page.dart';
  5. import 'Mine_page.dart';
  6. import 'Orders_page.dart';
  7. class IndexPage extends StatefulWidget {
  8. _IndexPageState createState() => _IndexPageState();
  9. }
  10. class _IndexPageState extends State<IndexPage> {
  11. final List<BottomNavigationBarItem> bottomTabs = [
  12. BottomNavigationBarItem(
  13. icon: Icon(CupertinoIcons.home),
  14. title: Text('首页'),
  15. ),
  16. BottomNavigationBarItem(
  17. icon: Icon(CupertinoIcons.search),
  18. title: Text('资讯'),
  19. ),
  20. BottomNavigationBarItem(
  21. icon: Icon(CupertinoIcons.shopping_cart),
  22. title: Text('订单'),
  23. ),
  24. BottomNavigationBarItem(
  25. icon: Icon(CupertinoIcons.profile_circled),
  26. title: Text('我的'),
  27. ),
  28. ];
  29. final List tabBodies = [
  30. HomePage(),
  31. InformationPage(),
  32. OrdersPage(),
  33. MinePage(),
  34. ];
  35. int currentIndex = 0;
  36. var currentPage;
  37. @override
  38. void initState() {
  39. super.initState();
  40. currentPage = tabBodies[currentIndex];
  41. }
  42. @override
  43. Widget build(BuildContext context) {
  44. // TODO: implement build
  45. return Scaffold(
  46. backgroundColor: Color.fromRGBO(244, 245, 245, 1),
  47. bottomNavigationBar: BottomNavigationBar(
  48. type: BottomNavigationBarType.fixed,
  49. currentIndex: currentIndex,
  50. items: bottomTabs,
  51. onTap: (index){
  52. setState(() {
  53. currentIndex = index;
  54. currentPage = tabBodies[currentIndex];
  55. });
  56. },
  57. ),
  58. body: currentPage,
  59. );
  60. }
  61. }