import 'dart:async'; import 'dart:ffi'; import 'package:flutter/material.dart'; import 'package:flutter_html/flutter_html.dart'; class HomePage extends StatefulWidget { const HomePage({Key? key}) : super(key: key); @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { // 模拟数据 final List> operations = [ { 'company': '通用电气-哈动力-南汽轮能源服务 (BSH) 有限公司', 'type': '动火作业', 'time': '2025-03-25 10:00', }, { 'company': '通用电气-哈动力-南汽轮能源服务 (秦皇岛) BRA', 'type': '高处作业', 'time': '2025-03-21 09:00', }, { 'company': '万基钢管 (秦皇岛) 有限公司', 'type': '高处作业', 'time': '2025-03-18 14:00', }, { 'company': '通用电气-哈动力-南汽轮能源服务 (BSH) 有限公司', 'type': '高处作业', 'time': '2025-03-17 11:20', }, { 'company': '通用电气-哈动力-南汽轮能源服务 (BSH) 有限公司', 'type': '动火作业', 'time': '2025-03-17 11:20', }, { 'company': '粤海中粤 (秦皇岛) 马口铁工业有限公司', 'type': '受限空间作业', 'time': '2025-03-07 09:28', }, { 'company': '粤海中粤 (秦皇岛) 马口铁工业有限公司', 'type': '高处作业', 'time': '2025-03-05 09:20', }, { 'company': '通用电气-哈动力-南汽轮能源服务 (BSH) 有限公司', 'type': '动火作业', 'time': '2025-02-26 14:40', }, ]; Future _onRefresh() async { // 模拟网络请求 await Future.delayed(const Duration(seconds: 2)); // 刷新数据逻辑,如 fetchData() setState(() { // TODO: 更新数据源 }); } @override Widget build(BuildContext context) { return Scaffold( body: RefreshIndicator( onRefresh: _onRefresh, child: ListView( physics: const AlwaysScrollableScrollPhysics(), children: [ _buildBgImage(), // _buildStatsCards(), const SizedBox(height: 24), _buildSectionTitle('企业排查情况'), const SizedBox(height: 12), _buildInspectionTable(), const SizedBox(height: 24), _buildSectionTitle('安全作业情况'), const SizedBox(height: 12), ..._buildOperationList(), ], ), ), ); } Widget _buildBgImage() { return Stack( alignment: const FractionalOffset(0.5, 1), children: [ Padding( // padding: EdgeInsetsGeometry.fromLTRB(0, 0, 0, 150), padding: EdgeInsets.only(bottom: 150), child: Image.asset( "assets/images/banner.png", width: MediaQuery.of(context).size.width, // 获取屏幕宽度 fit: BoxFit.cover), ), _buildStatsCards(), ], ); } Widget _buildStatsCards() { return Container( padding: const EdgeInsets.all(12), margin: EdgeInsets.fromLTRB(12,0,12,0), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(12), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.05), blurRadius: 8, offset: const Offset(0, 4), ) ], ), child: GridView.count( shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), crossAxisCount: 4, crossAxisSpacing: 16, mainAxisSpacing: 16, // childAspectRatio: 1.5, children: [ _buildStatCard(1,'企业信息', "assets/images/ico1.png"), _buildStatCard(2,'双重预防', "assets/images/ico2.png"), _buildStatCard(3,'重点安全', "assets/images/ico4.png"), _buildStatCard(4,'监管帮扶', "assets/images/ico9.png"), _buildStatCard(5,'专项检查', "assets/images/ico8.png"), _buildStatCard(6,'防灾减灾', "assets/images/ico10.png"), ], ), ); } Widget _buildStatCard(int id,String title, String icon ){ return GestureDetector( onTap: () { if(1==id){ // Navigator.pushReplacement( // context, // MaterialPageRoute(builder: (context) => const DangerPage()), // ); }else if(2==id){ }else if(3==id){ }else if(4==id){ }else if(5==id){ }else if(6==id){ } }, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ // Container( // padding: const EdgeInsets.all(12), // decoration: BoxDecoration( // color: color.withOpacity(0.1), // shape: BoxShape.circle, // ), Image.asset(icon,width: 30,height: 30,fit:BoxFit.cover), // child: Icon(icon, color: color, size: 32), // ), // const SizedBox(height: 12), Padding( // padding: EdgeInsetsGeometry.fromLTRB(0,5,0,0), padding: EdgeInsets.only(top: 5), child: Text(title, style: const TextStyle(fontSize: 16)) ) ], ), ); } Widget _buildSectionTitle(String title) { return Row( children: [ Container( margin: EdgeInsets.fromLTRB(12,0,12,0), width: 4, height: 20, decoration: BoxDecoration( color: const Color(0xFF0D47A1), borderRadius: BorderRadius.circular(2), ), ), const SizedBox(width: 8), Text(title, style: Theme.of(context).textTheme.titleMedium), ], ); } Widget _buildInspectionTable() { return Container( margin: EdgeInsets.fromLTRB(12,0,12,0), padding: const EdgeInsets.fromLTRB(16,16,16,10), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(12), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.05), blurRadius: 8, offset: const Offset(0, 4), ) ], ), child: Table( columnWidths: const { 0: FlexColumnWidth(2), 1: FlexColumnWidth(1), 2: FlexColumnWidth(1), }, border: TableBorder( horizontalInside: BorderSide(color: Colors.grey[200]!), verticalInside: BorderSide(color: Colors.grey[200]!), ), children: [ TableRow( decoration: BoxDecoration(color: Colors.grey[100]), children: [ _buildTableCell('各单位的管辖企业数',Colors.black, isHeader: true), _buildTableCell('已排查', Colors.black,isHeader: true), _buildTableCell('未排查',Colors.black, isHeader: true), ], ), TableRow( children: [ _buildTableCell('49',Colors.blue), _buildTableCell('36',Colors.green), _buildTableCell('13',Colors.orange), ], ), ], ), ); } Widget _buildTableCell(String text, Color color, {bool isHeader = false}) { return Padding( padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 8), child: Text( text, style: TextStyle( fontSize: 14, fontWeight: isHeader ? FontWeight.bold : FontWeight.normal, // color: isHeader ? const Color(0xFF333333) : const Color(0xFF666666), color:color, ), textAlign: TextAlign.center, ), ); } List _buildOperationList() { return [ Container( margin: EdgeInsets.fromLTRB(12,0,12,0), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(12), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.05), blurRadius: 8, offset: const Offset(0, 4), ) ], ), child: Column( children: [ for (int i = 0; i < operations.length; i++) _buildOperationItem(operations[i], i), ], ), ), ]; } Widget _buildOperationItem(Map operation, int index) { return Container( width: MediaQuery.of(context).size.width, // 获取屏幕宽度 decoration: BoxDecoration( border: Border( bottom: index < operations.length - 1 ? BorderSide(color: Colors.grey[200]!) : BorderSide.none, ), ), padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // Row( // mainAxisAlignment: MainAxisAlignment.spaceBetween, // children: [ Text( operation['company']!, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF333333)), // maxLines: 1, // overflow: TextOverflow.ellipsis, ), // ], // ), const SizedBox(height: 8), Container( padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), decoration: BoxDecoration( color: _getOperationColor(operation['type']!).withOpacity(0.1), borderRadius: BorderRadius.circular(4), ), child: Text( operation['type']!, style: TextStyle( fontSize: 12, fontWeight: FontWeight.bold, color: _getOperationColor(operation['type']!), ), ), ), const SizedBox(height: 8), Text( '作业时间: ${operation['time']}', style: const TextStyle(fontSize: 14, color: Color(0xFF666666)), ), ], ), ); } Color _getOperationColor(String type) { switch (type) { case '动火作业': return Colors.red; case '高处作业': return Colors.orange; case '受限空间作业': return Colors.purple; default: return Colors.blue; } } }