1. import 'package:flutter/material.dart';
    2. import 'home.dart';
    3. import 'search.dart';
    4. class MyBottomNavigationBar extends StatefulWidget {
    5. final int index;
    6. MyBottomNavigationBar({this.index = 0});
    7. @override
    8. _MyBottomNavigationBarState createState() =>
    9. _MyBottomNavigationBarState(this.index);
    10. }
    11. class _MyBottomNavigationBarState extends State<MyBottomNavigationBar> {
    12. _MyBottomNavigationBarState(index) {
    13. this._currentIndex = index;
    14. }
    15. int _currentIndex = 0;
    16. List _pageList = [
    17. HomePage(),
    18. SearchPage(),
    19. ];
    20. @override
    21. Widget build(BuildContext context) {
    22. return Scaffold(
    23. appBar: AppBar(
    24. title: Text('Hello Flutter'),
    25. ),
    26. body: this._pageList[this._currentIndex],
    27. bottomNavigationBar: BottomNavigationBar(
    28. currentIndex: _currentIndex,
    29. onTap: (int index) {
    30. setState(() {
    31. this._currentIndex = index;
    32. });
    33. },
    34. // iconSize: 20,
    35. // fixedColor: Colors.pink,
    36. type: BottomNavigationBarType.fixed, // 配置多个tabItem
    37. items: [
    38. BottomNavigationBarItem(
    39. icon: Icon(Icons.home),
    40. label: '首页',
    41. ),
    42. BottomNavigationBarItem(
    43. icon: Icon(Icons.search),
    44. label: '搜索',
    45. ),
    46. ],
    47. ),
    48. // Drawer
    49. drawer: Drawer(
    50. // child: DrawerHeader(child: Text('DrawerHeader')),
    51. child: UserAccountsDrawerHeader(
    52. accountName: Text('lynn'),
    53. accountEmail: Text('lynn@163.com'),
    54. otherAccountsPictures: [
    55. Image.network('https://images.pexels.com/photos/6922718/pexels-photo-6922718.jpeg?cs=srgb&dl=pexels-kira-schwarz-6922718.jpg&fm=jpg')
    56. ],
    57. ),
    58. ),
    59. );
    60. }
    61. }