index.dart 3.5KB

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