home_page.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 '../print/print_page.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. 'https://gd-hbimg.huaban.com/c7a22fb15d70a0a976e20fb810c048ec11c76fc31ac08-hajElf_fw658webp',
  16. 'https://gd-hbimg.huaban.com/82e60fd3c61530d52ec1d01f80cfda11526c42e4495cb-6JwN1d_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. ),
  44. Expanded(
  45. child: SingleChildScrollView(
  46. physics: const BouncingScrollPhysics(),
  47. child: Column(
  48. children: [
  49. buildBanner(),
  50. const SizedBox(height: 18),
  51. ...List.generate(
  52. serviceList.length,
  53. (index) => buildServiceItem(serviceList[index]),
  54. ).toList(),
  55. ],
  56. ),
  57. ),
  58. ),
  59. ],
  60. );
  61. }
  62. Widget buildScan() {
  63. return GestureDetector(
  64. onTap: MyRouter.startQrCodeScan,
  65. behavior: HitTestBehavior.opaque,
  66. child: Container(
  67. padding: const EdgeInsets.symmetric(horizontal: 16),
  68. alignment: Alignment.center,
  69. child: Image.asset(imgHomeScan, height: 24,width: 24),
  70. ),
  71. );
  72. }
  73. Widget buildBanner() {
  74. return Container(
  75. margin: const EdgeInsets.symmetric(horizontal: 12),
  76. decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(18))),
  77. clipBehavior: Clip.hardEdge,
  78. child: AspectRatio(
  79. aspectRatio: 2 / 1,
  80. child: Swiper(
  81. autoplay: true,
  82. autoplayDelay: const Duration(seconds: 5).inMilliseconds,
  83. itemCount: bannerList.length,
  84. itemBuilder: (_, index) => CachedNetworkImage(
  85. fit: BoxFit.cover,
  86. imageUrl: bannerList[index],
  87. placeholder: (_, __) => const Center(child: CircularProgressIndicator()),
  88. errorWidget: (context, url, error) => const Center(child: Icon(Icons.error)),
  89. ),
  90. ),
  91. ),
  92. );
  93. }
  94. Widget buildServiceItem(ServiceModel service) {
  95. return GestureDetector(
  96. onTap: service.onTap,
  97. child: Container(
  98. margin: const EdgeInsets.only(left: 12, right: 12, bottom: 22),
  99. padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 40),
  100. clipBehavior: Clip.hardEdge,
  101. decoration: BoxDecoration(
  102. borderRadius: const BorderRadius.all(Radius.circular(12)),
  103. boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.1), offset: const Offset(0, 5), blurRadius: 4)],
  104. image: const DecorationImage(image: AssetImage(imgHomeListBg), fit: BoxFit.fill),
  105. ),
  106. child: Row(
  107. children: [
  108. Image.asset(service.icon, height: 64),
  109. const SizedBox(width: 12),
  110. Expanded(
  111. child: Column(
  112. mainAxisSize: MainAxisSize.min,
  113. children: [
  114. Text(
  115. service.name,
  116. textAlign: TextAlign.center,
  117. style: const TextStyle(color: Color(0xFF333333), fontSize: 20, fontWeight: FontWeight.w500),
  118. ),
  119. service.nameEn != null
  120. ? Padding(
  121. padding: const EdgeInsets.only(top: 4),
  122. child: Text(
  123. service.nameEn!,
  124. textAlign: TextAlign.center,
  125. style: const TextStyle(color: Color(0xFF333333), fontSize: 12, fontWeight: FontWeight.w500),
  126. ),
  127. )
  128. : const SizedBox.shrink(),
  129. ],
  130. ),
  131. ),
  132. ],
  133. ),
  134. ),
  135. );
  136. }
  137. @override
  138. bool get wantKeepAlive => true;
  139. }
  140. class ServiceModel {
  141. final String name;
  142. final String? nameEn;
  143. final String icon;
  144. final VoidCallback onTap;
  145. ServiceModel({
  146. required this.name,
  147. this.nameEn,
  148. required this.icon,
  149. required this.onTap,
  150. });
  151. }