home_page.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. icon: const Icon(Icons.image,color: Colors.white,),
  78. onPressed: (){
  79. Navigator.push(context, MaterialPageRoute(builder: (ctx){
  80. return StockPointsWidget(
  81. width: 24,
  82. length: 10,
  83. height: 9.6,
  84. kWidth: MediaQuery.of(context).size.width - 8,
  85. kHeight: MediaQuery.of(context).size.height - 8 ,
  86. );
  87. }));
  88. },
  89. );
  90. }
  91. Widget buildBanner() {
  92. return Container(
  93. margin: const EdgeInsets.symmetric(horizontal: 12),
  94. decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(18))),
  95. clipBehavior: Clip.hardEdge,
  96. child: AspectRatio(
  97. aspectRatio: 2 / 1,
  98. child: Swiper(
  99. autoplay: true,
  100. autoplayDelay: const Duration(seconds: 5).inMilliseconds,
  101. itemCount: bannerList.length,
  102. itemBuilder: (_, index) => CachedNetworkImage(
  103. fit: BoxFit.cover,
  104. imageUrl: bannerList[index],
  105. placeholder: (_, __) => const Center(child: CircularProgressIndicator()),
  106. errorWidget: (context, url, error) => const Center(child: Icon(Icons.error)),
  107. ),
  108. ),
  109. ),
  110. );
  111. }
  112. Widget buildServiceItem(ServiceModel service) {
  113. double sW = MediaQuery.of(context).size.width-24;
  114. return GestureDetector(
  115. onTap: service.onTap,
  116. child: Container(
  117. width: sW,
  118. height: sW * 0.294,
  119. margin: const EdgeInsets.only(left: 12, right: 12, bottom: 18),
  120. decoration: BoxDecoration(
  121. borderRadius: const BorderRadius.all(Radius.circular(12)),
  122. boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.1), offset: const Offset(0, 5), blurRadius: 4)],
  123. image: DecorationImage(image: AssetImage(service.icon), fit: BoxFit.cover),
  124. ),
  125. ),
  126. );
  127. }
  128. @override
  129. bool get wantKeepAlive => true;
  130. }
  131. class ServiceModel {
  132. final String name;
  133. final String? nameEn;
  134. final Color? bgColor;
  135. final String icon;
  136. final VoidCallback onTap;
  137. ServiceModel({
  138. required this.name,
  139. this.nameEn,
  140. this.bgColor,
  141. required this.icon,
  142. required this.onTap,
  143. });
  144. }