index.dart 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import 'package:farmer_client/pages/home/widgets/Information/index.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:farmer_client/pages/home/widgets/main/index.dart';
  5. import 'package:farmer_client/pages/home/widgets/order/index.dart';
  6. class Home extends StatefulWidget {
  7. const Home({Key? key}) : super(key: key);
  8. @override
  9. _Home createState() => _Home();
  10. }
  11. class _Home extends State<Home> {
  12. //下标 当前tab
  13. int _tabIndex = 0;
  14. final List _titles = ['首页', '订单', '资讯','我的'];
  15. final tabTextStyleSelected = TextStyle(
  16. color: const Color(0xFFFF703B),
  17. fontSize: 15.sp,
  18. fontWeight: FontWeight.bold); //选线卡选中字体颜色
  19. final tabTextStyleNormal = TextStyle(
  20. color: const Color(0xFF323232),
  21. fontSize: 15.sp,
  22. fontWeight: FontWeight.bold); //选项卡未选中字体颜色
  23. TextStyle getTabTextStyle(int curIndex) {
  24. //设置tabbar 选中和未选中的状态文本
  25. if (curIndex == _tabIndex) {
  26. return tabTextStyleSelected;
  27. }
  28. return tabTextStyleNormal;
  29. }
  30. // 切换底部选项卡,标题的变化设置
  31. Text getTabTitle(int curIndex) {
  32. return Text(_titles[curIndex], style: getTabTextStyle(curIndex));
  33. }
  34. List images = [
  35. ['images/index/HomesOFFImgaes.png', 'images/index/HomesNOImgaes.png'],
  36. ['images/index/OrdersOFFImgaes.png', 'images/index/OrdersNOImgaes.png'],
  37. ['images/index/newsONImages.png', 'images/index/newsOFFImages.png'],
  38. ['images/index/MineOFFImgaes.png', 'images/index/MineNOImgaes.png'],
  39. ];
  40. Image getTabIcon(int curIndex) {
  41. //设置tabbar选中和未选中的状态图标
  42. if (curIndex == _tabIndex) {
  43. return Image.asset(
  44. images[curIndex][1],
  45. width: 22.w,
  46. height: 22.w,
  47. );
  48. }
  49. return Image.asset(
  50. images[curIndex][0],
  51. width: 22.w,
  52. height: 22.w,
  53. );
  54. }
  55. Image getTabImage(path) {
  56. return Image.asset(path, width: 22.w, height: 22.w);
  57. }
  58. //内容
  59. var _body = [Text('我是首页'), OrderPage(),Information(), MainPage()];
  60. Widget tabBar(index) {
  61. return GestureDetector(
  62. behavior: HitTestBehavior.opaque,
  63. onTap: () {
  64. setState(() {
  65. _tabIndex = index;
  66. });
  67. },
  68. child: Container(
  69. width: 93.w,
  70. height: 65.h,
  71. child: Column(
  72. children: [
  73. getTabIcon(index),
  74. Padding(
  75. padding: EdgeInsets.fromLTRB(0, 6.h, 0, 0),
  76. child: getTabTitle(index),
  77. )
  78. ],
  79. ),
  80. ),
  81. );
  82. }
  83. @override
  84. Widget build(BuildContext context) {
  85. return Scaffold(
  86. appBar: AppBar(
  87. elevation: 0,
  88. centerTitle: true,
  89. backgroundColor: Colors.white,
  90. title: Text(
  91. _titles[_tabIndex],
  92. style: TextStyle(
  93. color: Colors.black,
  94. fontSize: 17.sp,
  95. letterSpacing: 2,
  96. fontWeight: FontWeight.bold),
  97. ),
  98. ),
  99. body: _body[_tabIndex],
  100. bottomNavigationBar: Container(
  101. padding: EdgeInsets.fromLTRB(0, 7.h, 0, 7.h),
  102. decoration: BoxDecoration(
  103. color: const Color(0xFFFFFFFF),
  104. boxShadow: [
  105. BoxShadow(
  106. color: const Color(0x14000000),
  107. offset: Offset(0, -2.w),
  108. blurRadius: 3.w,
  109. ),
  110. ],
  111. ),
  112. child: Row(
  113. children:_titles.asMap().keys.map((index) =>tabBar(index)).toList(),
  114. ),
  115. ),
  116. );
  117. }
  118. }