home_page.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:card_swiper/card_swiper.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:lszlgl/base/base_state.dart';
  5. import 'package:lszlgl/page/sample_task/sample_task_list_tab_page.dart';
  6. import 'package:lszlgl/widget/stock_points_widget.dart';
  7. /// 首页
  8. class HomePage extends StatefulWidget {
  9. const HomePage({Key? key}) : super(key: key);
  10. @override
  11. State<HomePage> createState() => _HomePageState();
  12. }
  13. class _HomePageState extends BaseState<HomePage> with AutomaticKeepAliveClientMixin {
  14. List<String> bannerList = [
  15. 'http://121.36.17.6:19000/quality/app/zsys.png',
  16. 'https://gd-hbimg.huaban.com/c7a22fb15d70a0a976e20fb810c048ec11c76fc31ac08-hajElf_fw658webp',
  17. ];
  18. late List<ServiceModel> serviceList;
  19. void startSampleList(StepType type) async {
  20. MyRouter.startSampleTaskList(SampleTaskListTabPageArgs(type: type));
  21. }
  22. @override
  23. void initState() {
  24. super.initState();
  25. serviceList = [
  26. ServiceModel(name: '收获环节', icon: imgHomeListPzjc, onTap: () => startSampleList(StepType.reap)),
  27. ServiceModel(name: '库存环节', icon: imgHomeListZcjy, onTap: () => startSampleList(StepType.stock)),
  28. ];
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. super.build(context);
  33. return myScaffold(child: buildBody());
  34. }
  35. Widget buildBody() {
  36. return Column(
  37. children: [
  38. myAppBar(
  39. title: '质量安全检验监测',
  40. autoLeading: false,
  41. naviBarColor: Colors.white,
  42. actions: [buildScan(),
  43. // imageTest()
  44. ],
  45. ),
  46. Expanded(
  47. child: SingleChildScrollView(
  48. physics: const BouncingScrollPhysics(),
  49. child: Column(
  50. children: [
  51. buildBanner(),
  52. const SizedBox(height: 18),
  53. ...List.generate(
  54. serviceList.length,
  55. (index) => buildServiceItem(serviceList[index]),
  56. ).toList(),
  57. ],
  58. ),
  59. ),
  60. ),
  61. ],
  62. );
  63. }
  64. Widget buildScan() {
  65. return GestureDetector(
  66. onTap: MyRouter.startQrCodeScan,
  67. behavior: HitTestBehavior.opaque,
  68. child: Container(
  69. padding: const EdgeInsets.symmetric(horizontal: 16),
  70. alignment: Alignment.center,
  71. child: Image.asset(imgHomeScan, height: 24,width: 24),
  72. ),
  73. );
  74. }
  75. Widget imageTest(){
  76. return IconButton(
  77. onPressed: (){
  78. Navigator.push(context, MaterialPageRoute(builder: (ctx){
  79. return StockPointsWidget(
  80. width: 24,
  81. length: 10,
  82. height: 9.6,
  83. kWidth: MediaQuery.of(context).size.width - 8,
  84. kHeight: MediaQuery.of(context).size.height - 8 ,
  85. );
  86. }));
  87. }, icon: const Icon(Icons.image,color: Colors.white,));
  88. }
  89. Widget buildBanner() {
  90. return Container(
  91. margin: const EdgeInsets.symmetric(horizontal: 12),
  92. decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(18))),
  93. clipBehavior: Clip.hardEdge,
  94. child: AspectRatio(
  95. aspectRatio: 2 / 1,
  96. child: Swiper(
  97. autoplay: true,
  98. autoplayDelay: const Duration(seconds: 5).inMilliseconds,
  99. itemCount: bannerList.length,
  100. itemBuilder: (_, index) => CachedNetworkImage(
  101. fit: BoxFit.cover,
  102. imageUrl: bannerList[index],
  103. placeholder: (_, __) => const Center(child: CircularProgressIndicator()),
  104. errorWidget: (context, url, error) => const Center(child: Icon(Icons.error)),
  105. ),
  106. ),
  107. ),
  108. );
  109. }
  110. Widget buildServiceItem(ServiceModel service) {
  111. double sW = MediaQuery.of(context).size.width-24;
  112. return GestureDetector(
  113. onTap: service.onTap,
  114. child: Container(
  115. width: sW,
  116. height: sW * 0.294,
  117. margin: const EdgeInsets.only(left: 12, right: 12, bottom: 18),
  118. decoration: BoxDecoration(
  119. borderRadius: const BorderRadius.all(Radius.circular(12)),
  120. boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.1), offset: const Offset(0, 5), blurRadius: 4)],
  121. image: DecorationImage(image: AssetImage(service.icon), fit: BoxFit.cover),
  122. ),
  123. ),
  124. );
  125. }
  126. @override
  127. bool get wantKeepAlive => true;
  128. }
  129. class ServiceModel {
  130. final String name;
  131. final String? nameEn;
  132. final Color? bgColor;
  133. final String icon;
  134. final VoidCallback onTap;
  135. ServiceModel({
  136. required this.name,
  137. this.nameEn,
  138. this.bgColor,
  139. required this.icon,
  140. required this.onTap,
  141. });
  142. }