基础组件库
 
 
 
 
 

77 lines
2.0 KiB

  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:cached_network_image/cached_network_image.dart';
  4. import 'package:zhiying_comm/zhiying_comm.dart';
  5. class HomePage extends StatefulWidget {
  6. HomePage({Key key}) : super(key: key);
  7. @override
  8. _HomePageState createState() => _HomePageState();
  9. }
  10. class _HomePageState extends State<HomePage> {
  11. int _currentIndex = 0;
  12. List<String> _tab = List();
  13. List<Widget> _contentWidgets = List();
  14. @override
  15. void initState() {
  16. _tab.add('首页');
  17. _tab.add('个人中心');
  18. _contentWidgets = _tab.map((item) {
  19. return PageFactory.create('mainPage', Map());
  20. }).toList();
  21. super.initState();
  22. }
  23. @override
  24. Widget build(BuildContext context) {
  25. print('home_page build');
  26. return Scaffold(
  27. body: IndexedStack(
  28. index: _currentIndex,
  29. children: _contentWidgets,
  30. ),
  31. //底部导航栏
  32. bottomNavigationBar: createBottomNavigationBar());
  33. }
  34. Widget createBottomNavigationBar() {
  35. List<BottomNavigationBarItem> items = List<BottomNavigationBarItem>();
  36. for (int i = 0; i < _tab.length; i++) {
  37. items.add(BottomNavigationBarItem(
  38. icon: Container(
  39. width: 24,
  40. height: 24,
  41. margin: EdgeInsets.only(bottom: 4),
  42. child: CachedNetworkImage(
  43. imageUrl:
  44. "http://www.hairuyi.com/Upload/slide/1594279903_1_0.png",
  45. fit: BoxFit.fitWidth,
  46. ),
  47. ),
  48. title: Text('tab2')));
  49. }
  50. if (items.length < 2) {
  51. return Container();
  52. }
  53. return BottomNavigationBar(
  54. backgroundColor: Colors.white,
  55. type: BottomNavigationBarType.fixed,
  56. selectedFontSize: 11,
  57. unselectedFontSize: 11,
  58. currentIndex: _currentIndex,
  59. elevation: 0,
  60. onTap: ((index) {
  61. setState(() {
  62. _currentIndex = index;
  63. });
  64. }),
  65. //底部导航栏
  66. items: items);
  67. }
  68. }