feat(mobile): #24 Flutter三合一APP骨架搭建
- Flutter 3.x 项目初始化(pubspec.yaml + 目录结构) - 核心依赖:dio/go_router/provider/shared_preferences/hive/geolocator - 统一登录页 + Token管理(TokenService + AuthInterceptor) - 底部Tab三合一导航(供水/巡检/营收) - 供水管理Tab:监测数据列表(MonitorListPage) - 巡检Tab:任务列表+状态筛选+进度展示(PatrolTaskListPage) - 营收Tab:抄表页面+账单列表(MeterReadingPage/BillListPage) - 消息推送服务(PushService) - GPS定位服务(LocationService) - 拍照/相册服务(CameraService) - 离线缓存服务(CacheService) - Android/iOS打包配置+权限声明 - GoRouter路由+Auth认证守卫 - Provider状态管理
This commit is contained in:
@@ -0,0 +1,255 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/patrol_task_model.dart';
|
||||
|
||||
/// 巡检任务列表页面
|
||||
class PatrolTaskListPage extends StatefulWidget {
|
||||
const PatrolTaskListPage({super.key});
|
||||
|
||||
@override
|
||||
State<PatrolTaskListPage> createState() => _PatrolTaskListPageState();
|
||||
}
|
||||
|
||||
class _PatrolTaskListPageState extends State<PatrolTaskListPage>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
List<PatrolTaskModel> _tasks = [];
|
||||
bool _isLoading = true;
|
||||
String _filterStatus = 'all';
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadData();
|
||||
}
|
||||
|
||||
void _loadData() {
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
setState(() {
|
||||
_tasks = _generateMockData();
|
||||
_isLoading = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
List<PatrolTaskModel> _generateMockData() {
|
||||
return [
|
||||
PatrolTaskModel(
|
||||
id: '1', taskName: '城东管网日常巡检', taskCode: 'PT-2024-001',
|
||||
routeName: '城东A线', assignee: '张工',
|
||||
status: 'in_progress', planDate: DateTime.now(),
|
||||
checkpointTotal: 12, checkpointCompleted: 7,
|
||||
),
|
||||
PatrolTaskModel(
|
||||
id: '2', taskName: '城西水厂设备巡检', taskCode: 'PT-2024-002',
|
||||
routeName: '城西厂区', assignee: '李工',
|
||||
status: 'pending', planDate: DateTime.now().add(const Duration(days: 1)),
|
||||
checkpointTotal: 8, checkpointCompleted: 0,
|
||||
),
|
||||
PatrolTaskModel(
|
||||
id: '3', taskName: '南区管网夜间巡检', taskCode: 'PT-2024-003',
|
||||
routeName: '南区B线', assignee: '王工',
|
||||
status: 'completed', planDate: DateTime.now().subtract(const Duration(days: 1)),
|
||||
checkpointTotal: 10, checkpointCompleted: 10,
|
||||
),
|
||||
PatrolTaskModel(
|
||||
id: '4', taskName: '北区调蓄池安全巡检', taskCode: 'PT-2024-004',
|
||||
routeName: '北区站点', assignee: '赵工',
|
||||
status: 'overdue', planDate: DateTime.now().subtract(const Duration(days: 2)),
|
||||
checkpointTotal: 6, checkpointCompleted: 2,
|
||||
),
|
||||
PatrolTaskModel(
|
||||
id: '5', taskName: '开发区阀门巡检', taskCode: 'PT-2024-005',
|
||||
routeName: '开发区C线', assignee: '刘工',
|
||||
status: 'pending', planDate: DateTime.now().add(const Duration(days: 2)),
|
||||
checkpointTotal: 15, checkpointCompleted: 0,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
List<PatrolTaskModel> get _filteredTasks {
|
||||
if (_filterStatus == 'all') return _tasks;
|
||||
return _tasks.where((t) => t.status == _filterStatus).toList();
|
||||
}
|
||||
|
||||
Color _getStatusColor(String status) {
|
||||
switch (status) {
|
||||
case 'pending': return Colors.blue;
|
||||
case 'in_progress': return Colors.orange;
|
||||
case 'completed': return Colors.green;
|
||||
case 'overdue': return Colors.red;
|
||||
default: return Colors.grey;
|
||||
}
|
||||
}
|
||||
|
||||
String _getStatusText(String status) {
|
||||
switch (status) {
|
||||
case 'pending': return '待执行';
|
||||
case 'in_progress': return '进行中';
|
||||
case 'completed': return '已完成';
|
||||
case 'overdue': return '已超期';
|
||||
default: return status;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('巡检任务'),
|
||||
bottom: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(48),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
_buildFilterChip('全部', 'all'),
|
||||
_buildFilterChip('待执行', 'pending'),
|
||||
_buildFilterChip('进行中', 'in_progress'),
|
||||
_buildFilterChip('已完成', 'completed'),
|
||||
_buildFilterChip('超期', 'overdue'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: _isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _filteredTasks.isEmpty
|
||||
? const Center(child: Text('暂无巡检任务'))
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.all(12),
|
||||
itemCount: _filteredTasks.length,
|
||||
itemBuilder: (context, index) {
|
||||
return _buildTaskCard(_filteredTasks[index]);
|
||||
},
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
// TODO: 新建巡检任务
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterChip(String label, String value) {
|
||||
final isSelected = _filterStatus == value;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: FilterChip(
|
||||
label: Text(label, style: const TextStyle(fontSize: 12)),
|
||||
selected: isSelected,
|
||||
onSelected: (selected) {
|
||||
setState(() {
|
||||
_filterStatus = value;
|
||||
});
|
||||
},
|
||||
selectedColor: const Color(0xFF1976D2).withOpacity(0.2),
|
||||
checkmarkColor: const Color(0xFF1976D2),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTaskCard(PatrolTaskModel task) {
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.assignment, color: Color(0xFF1976D2), size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
task.taskName,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
task.taskCode,
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey[500]),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: _getStatusColor(task.status).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
_getStatusText(task.status),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: _getStatusColor(task.status),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
_buildInfoItem(Icons.route, '路线: ${task.routeName}'),
|
||||
const SizedBox(width: 16),
|
||||
_buildInfoItem(Icons.person, '巡检人: ${task.assignee}'),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// 进度条
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'巡检进度: ${task.checkpointCompleted}/${task.checkpointTotal}',
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'${(task.progress * 100).toStringAsFixed(0)}%',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: _getStatusColor(task.status),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: LinearProgressIndicator(
|
||||
value: task.progress,
|
||||
backgroundColor: Colors.grey[200],
|
||||
valueColor: AlwaysStoppedAnimation(_getStatusColor(task.status)),
|
||||
minHeight: 6,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoItem(IconData icon, String text) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 14, color: Colors.grey[600]),
|
||||
const SizedBox(width: 4),
|
||||
Text(text, style: TextStyle(fontSize: 13, color: Colors.grey[700])),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user