index.dart 3.6KB

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