navigation.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import 'package:flutter/material.dart';
  2. import 'home.dart';
  3. import 'mine.dart';
  4. void main() {
  5. WidgetsFlutterBinding.ensureInitialized();
  6. runApp(BottomNavigationWidget());
  7. }
  8. class BottomNavigationWidget extends StatefulWidget {
  9. @override
  10. _BottomNavigationWidgetState createState() => _BottomNavigationWidgetState();
  11. }
  12. class _BottomNavigationWidgetState extends State<BottomNavigationWidget> {
  13. final bottomNavigationColor = Colors.blue;
  14. int curIndex = 0;
  15. List<Widget> pages = [];
  16. @override
  17. void initState() {
  18. super.initState();
  19. }
  20. @override
  21. Widget build(BuildContext context) {
  22. pages
  23. ..add(Home(context))
  24. ..add(Mine());
  25. return MaterialApp(
  26. home: Scaffold(
  27. body: pages[curIndex],
  28. bottomNavigationBar: BottomNavigationBar(
  29. items: [
  30. BottomNavigationBarItem(
  31. icon: Icon(Icons.home, color: bottomNavigationColor),
  32. label: '首页',
  33. // title: Text('home1', style: TextStyle(color: bottomNavigationColor))
  34. ),
  35. BottomNavigationBarItem(
  36. icon: Icon(Icons.person, color: bottomNavigationColor),
  37. label: '我的',
  38. // title: Text('home', style: TextStyle(color: bottomNavigationColor))
  39. )
  40. ],
  41. currentIndex: curIndex,
  42. onTap: (int index) {
  43. setState(() {
  44. curIndex = index;
  45. });
  46. },
  47. fixedColor: Colors.blue,
  48. type: BottomNavigationBarType.fixed,
  49. ),
  50. ),
  51. );
  52. }
  53. }