bottom_navigation.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. }