home_page.dart 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. var args = PrintPageArgs(count: 0);
  21. await MyRouter.startPrint(args: args);
  22. // MyRouter.startSampleTaskList(SampleTaskListTabPageArgs(type: type));
  23. }
  24. @override
  25. void initState() {
  26. super.initState();
  27. serviceList = [
  28. ServiceModel(name: '收获环节', icon: imgHomeListPzjc, onTap: () => startSampleList(StepType.reap)),
  29. ServiceModel(name: '库存环节', icon: imgHomeListZcjy, onTap: () => startSampleList(StepType.stock)),
  30. ];
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. super.build(context);
  35. return myScaffold(child: buildBody());
  36. }
  37. Widget buildBody() {
  38. return Column(
  39. children: [
  40. myAppBar(
  41. title: '质量安全检验监测',
  42. autoLeading: false,
  43. naviBarColor: Colors.white,
  44. ),
  45. Expanded(
  46. child: SingleChildScrollView(
  47. physics: const BouncingScrollPhysics(),
  48. child: Column(
  49. children: [
  50. buildBanner(),
  51. const SizedBox(height: 18),
  52. ...List.generate(
  53. serviceList.length,
  54. (index) => buildServiceItem(serviceList[index]),
  55. ).toList(),
  56. ],
  57. ),
  58. ),
  59. ),
  60. ],
  61. );
  62. }
  63. Widget buildBanner() {
  64. return Container(
  65. margin: const EdgeInsets.symmetric(horizontal: 12),
  66. decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(18))),
  67. clipBehavior: Clip.hardEdge,
  68. child: AspectRatio(
  69. aspectRatio: 2 / 1,
  70. child: Swiper(
  71. autoplay: true,
  72. autoplayDelay: const Duration(seconds: 5).inMilliseconds,
  73. itemCount: bannerList.length,
  74. itemBuilder: (_, index) => CachedNetworkImage(
  75. fit: BoxFit.cover,
  76. imageUrl: bannerList[index],
  77. placeholder: (_, __) => const Center(child: CircularProgressIndicator()),
  78. errorWidget: (context, url, error) => const Center(child: Icon(Icons.error)),
  79. ),
  80. ),
  81. ),
  82. );
  83. }
  84. Widget buildServiceItem(ServiceModel service) {
  85. return GestureDetector(
  86. onTap: service.onTap,
  87. child: Container(
  88. margin: const EdgeInsets.only(left: 12, right: 12, bottom: 22),
  89. padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 40),
  90. clipBehavior: Clip.hardEdge,
  91. decoration: BoxDecoration(
  92. borderRadius: const BorderRadius.all(Radius.circular(12)),
  93. boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.1), offset: const Offset(0, 5), blurRadius: 4)],
  94. image: const DecorationImage(image: AssetImage(imgHomeListBg), fit: BoxFit.fill),
  95. ),
  96. child: Row(
  97. children: [
  98. Image.asset(service.icon, height: 64),
  99. const SizedBox(width: 12),
  100. Expanded(
  101. child: Column(
  102. mainAxisSize: MainAxisSize.min,
  103. children: [
  104. Text(
  105. service.name,
  106. textAlign: TextAlign.center,
  107. style: const TextStyle(color: Color(0xFF333333), fontSize: 20, fontWeight: FontWeight.w500),
  108. ),
  109. service.nameEn != null
  110. ? Padding(
  111. padding: const EdgeInsets.only(top: 4),
  112. child: Text(
  113. service.nameEn!,
  114. textAlign: TextAlign.center,
  115. style: const TextStyle(color: Color(0xFF333333), fontSize: 12, fontWeight: FontWeight.w500),
  116. ),
  117. )
  118. : const SizedBox.shrink(),
  119. ],
  120. ),
  121. ),
  122. ],
  123. ),
  124. ),
  125. );
  126. }
  127. @override
  128. bool get wantKeepAlive => true;
  129. }
  130. class ServiceModel {
  131. final String name;
  132. final String? nameEn;
  133. final String icon;
  134. final VoidCallback onTap;
  135. ServiceModel({
  136. required this.name,
  137. this.nameEn,
  138. required this.icon,
  139. required this.onTap,
  140. });
  141. }