基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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