home_page.dart 4.7 KB

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