navigation.dart 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 Scaffold(
  26. body: pages[curIndex],
  27. bottomNavigationBar: BottomNavigationBar(
  28. items: [
  29. BottomNavigationBarItem(
  30. icon: Icon(Icons.home, color: bottomNavigationColor),
  31. label: '首页',
  32. // title: Text('home1', style: TextStyle(color: bottomNavigationColor))
  33. ),
  34. BottomNavigationBarItem(
  35. icon: Icon(Icons.person, color: bottomNavigationColor),
  36. label: '我的',
  37. // title: Text('home', style: TextStyle(color: bottomNavigationColor))
  38. )
  39. ],
  40. currentIndex: curIndex,
  41. onTap: (int index) {
  42. setState(() {
  43. curIndex = index;
  44. });
  45. },
  46. fixedColor: Colors.blue,
  47. type: BottomNavigationBarType.fixed,
  48. ),
  49. );
  50. }
  51. }