home2.dart 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. class Home extends StatefulWidget {
  6. const Home({Key? key}) : super(key: key);
  7. @override
  8. _Home createState() => _Home();
  9. }
  10. class _Home extends State<Home> {
  11. List images = [
  12. ['images/index/index.png', 'images/index/indexActive.png'],
  13. ['images/index/job.png', 'images/index/jobActive.png'],
  14. ['images/index/user.png', 'images/index/userActive.png'],
  15. ];
  16. final List _titles = ['首页', '订单列表', '个人中心'];
  17. int _currentIndex = 0;
  18. final tabTextStyleSelected =
  19. TextStyle(color: const Color(0xFF06B03B),fontSize: 15.sp,fontWeight: FontWeight.bold); //选线卡选中字体颜色
  20. final tabTextStyleNormal =
  21. TextStyle(color: const Color(0xFF323232),fontSize: 15.sp,fontWeight: FontWeight.bold); //选项卡未选中字体颜色
  22. int _tabIndex = 0; //选项卡下标
  23. var _body = [Text('我是首页'), Text('我是订单列表'), Text('我是个人中心')];
  24. TextStyle getTabTextStyle(int curIndex) {
  25. //设置tabbar 选中和未选中的状态文本
  26. if (curIndex == _tabIndex) {
  27. return tabTextStyleSelected;
  28. }
  29. return tabTextStyleNormal;
  30. }
  31. Image getTabIcon(int curIndex) {
  32. //设置tabbar选中和未选中的状态图标
  33. if (curIndex == _tabIndex) {
  34. return Image.asset(
  35. images[curIndex][1],
  36. width: 20.w,
  37. height: 20.w,
  38. );
  39. }
  40. return Image.asset(
  41. images[curIndex][0],
  42. width: 20.w,
  43. height: 20.w,
  44. );
  45. }
  46. Image getTabImage(path) {
  47. return Image.asset(path, width: 26.w, height: 26.w);
  48. }
  49. // 切换底部选项卡,标题的变化设置
  50. Text getTabTitle(int curIndex) {
  51. return Text(_titles[curIndex], style: getTabTextStyle(curIndex));
  52. }
  53. @override
  54. Widget build(BuildContext context) {
  55. return Scaffold(
  56. appBar: AppBar(
  57. elevation: 0,
  58. centerTitle: true,
  59. backgroundColor: Colors.white,
  60. title: Text(
  61. '首页',
  62. style: TextStyle(
  63. color: Colors.black,
  64. fontSize: 17.sp,
  65. letterSpacing: 2,
  66. fontWeight: FontWeight.bold
  67. ),
  68. ),
  69. ),
  70. body: _body[_tabIndex],
  71. bottomNavigationBar: Container(
  72. height: 65.h,
  73. child: Row(
  74. mainAxisAlignment: MainAxisAlignment.spaceAround,
  75. children: [
  76. Column(
  77. children: [
  78. getTabIcon(0),
  79. getTabTitle(0)
  80. ],
  81. ),
  82. Column(
  83. children: [
  84. getTabIcon(1),
  85. getTabTitle(1)
  86. ],
  87. ),
  88. Column(
  89. children: [
  90. getTabIcon(2),
  91. getTabTitle(2)
  92. ],
  93. ),
  94. ],
  95. ),
  96. ),
  97. );
  98. }
  99. }