home_page.dart 5.1 KB

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