index_page.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_tracker/pages/home_page.dart';
  3. import 'package:flutter_tracker/pages/mine_page.dart';
  4. import 'package:flutter_tracker/pages/track_page.dart';
  5. class IndexPage extends StatefulWidget {
  6. const IndexPage({Key key}) : super(key: key);
  7. @override
  8. _IndexPageState createState() => _IndexPageState();
  9. }
  10. class _IndexPageState extends State<IndexPage> {
  11. int navIndex = 0;
  12. List<Widget> pages = [
  13. const HomePage(),
  14. const TrackPage(),
  15. const MinePage(),
  16. ];
  17. Widget currentPage;
  18. @override
  19. void initState() {
  20. super.initState();
  21. currentPage = pages[navIndex];
  22. }
  23. @override
  24. Widget build(BuildContext context) {
  25. return Scaffold(
  26. backgroundColor: const Color(0xF1F6F9ff),
  27. body: currentPage,
  28. bottomNavigationBar: BottomNavigationBar(
  29. type: BottomNavigationBarType.fixed,
  30. currentIndex: navIndex,
  31. items: const [
  32. BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
  33. BottomNavigationBarItem(
  34. icon: Icon(Icons.art_track), label: "追踪"),
  35. BottomNavigationBarItem(icon: Icon(Icons.person), label: "我的"),
  36. ],
  37. onTap: (index) {
  38. setState(() {
  39. navIndex = index;
  40. currentPage = pages[navIndex];
  41. });
  42. },
  43. ),
  44. );
  45. }
  46. }