123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:card_swiper/card_swiper.dart';
- import 'package:flutter/material.dart';
- import 'package:lszlgl/base/base_state.dart';
- import 'package:lszlgl/page/sample_task/sample_task_list_tab_page.dart';
- import '../print/print_page.dart';
- /// 首页
- class HomePage extends StatefulWidget {
- const HomePage({Key? key}) : super(key: key);
- @override
- State<HomePage> createState() => _HomePageState();
- }
- class _HomePageState extends BaseState<HomePage> with AutomaticKeepAliveClientMixin {
- List<String> bannerList = [
- 'https://gd-hbimg.huaban.com/c7a22fb15d70a0a976e20fb810c048ec11c76fc31ac08-hajElf_fw658webp',
- 'https://gd-hbimg.huaban.com/82e60fd3c61530d52ec1d01f80cfda11526c42e4495cb-6JwN1d_fw658webp',
- ];
- late List<ServiceModel> serviceList;
- void startSampleList(StepType type) async {
- MyRouter.startSampleTaskList(SampleTaskListTabPageArgs(type: type));
- }
- @override
- void initState() {
- super.initState();
- serviceList = [
- ServiceModel(name: '收获环节', icon: imgHomeListPzjc, onTap: () => startSampleList(StepType.reap)),
- ServiceModel(name: '库存环节', icon: imgHomeListZcjy, onTap: () => startSampleList(StepType.stock)),
- ];
- }
- @override
- Widget build(BuildContext context) {
- super.build(context);
- return myScaffold(child: buildBody());
- }
- Widget buildBody() {
- return Column(
- children: [
- myAppBar(
- title: '质量安全检验监测',
- autoLeading: false,
- naviBarColor: Colors.white,
- actions: [buildScan()],
- ),
- Expanded(
- child: SingleChildScrollView(
- physics: const BouncingScrollPhysics(),
- child: Column(
- children: [
- buildBanner(),
- const SizedBox(height: 18),
- ...List.generate(
- serviceList.length,
- (index) => buildServiceItem(serviceList[index]),
- ).toList(),
- ],
- ),
- ),
- ),
- ],
- );
- }
- Widget buildScan() {
- return GestureDetector(
- onTap: MyRouter.startQrCodeScan,
- behavior: HitTestBehavior.opaque,
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- alignment: Alignment.center,
- child: Image.asset(imgHomeScan, height: 24,width: 24),
- ),
- );
- }
- Widget buildBanner() {
- return Container(
- margin: const EdgeInsets.symmetric(horizontal: 12),
- decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(18))),
- clipBehavior: Clip.hardEdge,
- child: AspectRatio(
- aspectRatio: 2 / 1,
- child: Swiper(
- autoplay: true,
- autoplayDelay: const Duration(seconds: 5).inMilliseconds,
- itemCount: bannerList.length,
- itemBuilder: (_, index) => CachedNetworkImage(
- fit: BoxFit.cover,
- imageUrl: bannerList[index],
- placeholder: (_, __) => const Center(child: CircularProgressIndicator()),
- errorWidget: (context, url, error) => const Center(child: Icon(Icons.error)),
- ),
- ),
- ),
- );
- }
- Widget buildServiceItem(ServiceModel service) {
- return GestureDetector(
- onTap: service.onTap,
- child: Container(
- margin: const EdgeInsets.only(left: 12, right: 12, bottom: 22),
- padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 40),
- clipBehavior: Clip.hardEdge,
- decoration: BoxDecoration(
- borderRadius: const BorderRadius.all(Radius.circular(12)),
- boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.1), offset: const Offset(0, 5), blurRadius: 4)],
- image: const DecorationImage(image: AssetImage(imgHomeListBg), fit: BoxFit.fill),
- ),
- child: Row(
- children: [
- Image.asset(service.icon, height: 64),
- const SizedBox(width: 12),
- Expanded(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- service.name,
- textAlign: TextAlign.center,
- style: const TextStyle(color: Color(0xFF333333), fontSize: 20, fontWeight: FontWeight.w500),
- ),
- service.nameEn != null
- ? Padding(
- padding: const EdgeInsets.only(top: 4),
- child: Text(
- service.nameEn!,
- textAlign: TextAlign.center,
- style: const TextStyle(color: Color(0xFF333333), fontSize: 12, fontWeight: FontWeight.w500),
- ),
- )
- : const SizedBox.shrink(),
- ],
- ),
- ),
- ],
- ),
- ),
- );
- }
- @override
- bool get wantKeepAlive => true;
- }
- class ServiceModel {
- final String name;
- final String? nameEn;
- final String icon;
- final VoidCallback onTap;
- ServiceModel({
- required this.name,
- this.nameEn,
- required this.icon,
- required this.onTap,
- });
- }
|