所有一级页面和不分二级页面

This commit is contained in:
2026-05-25 12:58:29 +08:00
parent b9f747de05
commit afef5c4ef1
158 changed files with 13082 additions and 1602 deletions

View File

@@ -0,0 +1,154 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
/// 媒体预览页面
class MediaPreviewPage extends StatefulWidget {
final List<String> mediaFiles;
final int initialIndex;
const MediaPreviewPage({
super.key,
required this.mediaFiles,
required this.initialIndex,
});
@override
State<MediaPreviewPage> createState() => _MediaPreviewPageState();
}
class _MediaPreviewPageState extends State<MediaPreviewPage> {
late PageController _pageController;
VideoPlayerController? _videoController;
int _currentIndex = 0;
@override
void initState() {
super.initState();
_currentIndex = widget.initialIndex;
_pageController = PageController(initialPage: widget.initialIndex);
_initializeVideo(widget.mediaFiles[_currentIndex]);
}
@override
void dispose() {
_pageController.dispose();
_videoController?.dispose();
super.dispose();
}
/// 初始化视频播放器
Future<void> _initializeVideo(String filePath) async {
// 先释放之前的控制器
await _videoController?.dispose();
_videoController = null;
if (_isVideoFile(filePath)) {
_videoController = VideoPlayerController.file(File(filePath));
try {
await _videoController!.initialize();
setState(() {});
} catch (e) {
debugPrint('视频初始化失败: $e');
}
}
}
/// 判断是否为视频文件
bool _isVideoFile(String filePath) {
final lowerPath = filePath.toLowerCase();
return lowerPath.endsWith('.mp4') ||
lowerPath.endsWith('.mov') ||
lowerPath.endsWith('.avi') ||
lowerPath.endsWith('.mkv') ||
lowerPath.endsWith('.wmv') ||
lowerPath.endsWith('.flv');
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.close, color: Colors.white),
onPressed: () => Navigator.pop(context),
),
title: Text(
'${_currentIndex + 1}/${widget.mediaFiles.length}',
style: const TextStyle(color: Colors.white),
),
centerTitle: true,
),
body: PageView.builder(
controller: _pageController,
itemCount: widget.mediaFiles.length,
onPageChanged: (index) {
setState(() {
_currentIndex = index;
});
_initializeVideo(widget.mediaFiles[index]);
},
itemBuilder: (context, index) {
final filePath = widget.mediaFiles[index];
if (_isVideoFile(filePath)) {
return _buildVideoPreview();
} else {
return _buildImagePreview(filePath);
}
},
),
);
}
/// 构建图片预览
Widget _buildImagePreview(String filePath) {
final bool isNetworkImage = filePath.startsWith('http');
return Center(
child: InteractiveViewer(
child: isNetworkImage
? Image.network(
filePath,
fit: BoxFit.contain,
errorBuilder: (context, error, stackTrace) {
return const Icon(
Icons.broken_image,
color: Colors.white,
size: 64,
);
},
)
: Image.file(
File(filePath),
fit: BoxFit.contain,
errorBuilder: (context, error, stackTrace) {
return const Icon(
Icons.broken_image,
color: Colors.white,
size: 64,
);
},
),
),
);
}
/// 构建视频预览
Widget _buildVideoPreview() {
if (_videoController == null || !_videoController!.value.isInitialized) {
return const Center(
child: CircularProgressIndicator(color: Colors.white),
);
}
return Center(
child: AspectRatio(
aspectRatio: _videoController!.value.aspectRatio,
child: VideoPlayer(_videoController!),
),
);
}
}

View File

@@ -0,0 +1,476 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import '../cubit/report_cubit.dart';
import '../states/report_state.dart';
import '../constants/report_constants.dart';
import '../widgets/report_type_selector.dart';
import '../widgets/device_selector.dart';
import '../widgets/description_input.dart';
import '../widgets/media_uploader.dart';
import '../widgets/level_selector.dart';
import 'media_preview_page.dart';
import '../../di/report_di.dart';
/// 现场上报主页面
class ReportPage extends StatelessWidget {
const ReportPage({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => ReportDependencyInjector.createReportCubit(),
child: _ReportPageContent(),
);
}
}
class _ReportPageContent extends StatelessWidget {
const _ReportPageContent();
@override
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.dark,
child: Scaffold(
backgroundColor: AppColors.cardBackground,
body: BlocConsumer<ReportCubit, ReportState>(
listener: (context, state) {
if (state is ReportSuccess) {
_showSuccessDialog(context);
} else if (state is ReportFailure) {
_showErrorDialog(context, state.message);
}
},
builder: (context, state) {
if (state is ReportSubmitting) {
return const Center(
child: CircularProgressIndicator(
color: AppColors.primary,
),
);
}
if (state is ReportFormState) {
final cubit = context.read<ReportCubit>();
return Column(
children: [
_buildAppBar(context, state.location, cubit),
Expanded(
child: _buildFormContent(context, state),
),
],
);
}
return const SizedBox.shrink();
},
),
),
);
}
/// 构建导航栏
PreferredSizeWidget _buildAppBar(BuildContext context, String location, ReportCubit cubit) {
return PreferredSize(
preferredSize: const Size.fromHeight(100),
child: Container(
color: AppColors.background,
child: SafeArea(
bottom: false,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: AppDimensions.horizontalPadding,
),
child: Column(
children: [
// 第一行:标题 + 提交按钮
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'现场上报',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: AppColors.textPrimary,
),
),
GestureDetector(
onTap: () {
context.read<ReportCubit>().submitReport();
},
child: const Text(
'提交',
style: TextStyle(
color: AppColors.primary,
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
),
],
),
const SizedBox(height: 12),
// 第二行:位置信息(可点击)
GestureDetector(
onTap: () {
_showLocationPicker(context, cubit);
},
child: Row(
children: [
const Icon(
Icons.location_on,
color: AppColors.primary,
size: 16,
),
const SizedBox(width: 6),
Flexible(
child: Text(
location,
style: TextStyle(
fontSize: 14,
color: AppColors.textSecondary,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 4),
Icon(
Icons.arrow_drop_down,
size: 20,
color: AppColors.textHint,
),
],
),
),
const SizedBox(height: 8),
],
),
),
),
),
);
}
/// 构建表单内容
Widget _buildFormContent(BuildContext context, ReportFormState state) {
final cubit = context.read<ReportCubit>();
return SingleChildScrollView(
padding: const EdgeInsets.only(
top: AppDimensions.moduleSpacing,
bottom: 40,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 上报类型选择
ReportTypeSelector(
selectedType: state.selectedReportType,
onSelected: (type) => cubit.selectReportType(type),
),
const SizedBox(height: AppDimensions.moduleSpacing),
// 设备选择
DeviceSelector(
selectedDevice: state.selectedDevice,
onTap: () {
_showDevicePicker(context, cubit);
},
),
const SizedBox(height: AppDimensions.moduleSpacing),
// 问题描述
DescriptionInput(
description: state.report.description,
onChanged: (value) => cubit.updateDescription(value),
),
const SizedBox(height: AppDimensions.moduleSpacing),
// 媒体上传
MediaUploader(
mediaFiles: state.mediaFiles,
onCameraTap: () {
_pickImage(cubit);
},
onVideoTap: () {
_pickVideo(cubit);
},
onAddFromGallery: () {
_pickFromGallery(context, cubit);
},
onTap: (index) {
_previewMedia(context, state.mediaFiles, index);
},
onRemove: (index) => cubit.removeMediaFile(index),
),
const SizedBox(height: AppDimensions.moduleSpacing),
// 问题等级选择
LevelSelector(
selectedLevel: state.selectedProblemLevel,
onSelected: (level) => cubit.selectProblemLevel(level),
),
const SizedBox(height: 40),
],
),
);
}
/// 构建位置信息行
Widget _buildLocationRow(BuildContext context, String location) {
return Container(
margin: const EdgeInsets.symmetric(
horizontal: AppDimensions.horizontalPadding,
),
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
decoration: BoxDecoration(
color: AppColors.background,
borderRadius: BorderRadius.circular(AppDimensions.borderRadius),
boxShadow: [
BoxShadow(
color: const Color(0x0D000000),
blurRadius: AppDimensions.cardShadowBlur,
offset: const Offset(0, 2),
),
],
),
child: Row(
children: [
const Icon(
Icons.location_on,
color: AppColors.primary,
size: 20,
),
const SizedBox(width: 8),
Expanded(
child: Text(
location,
style: TextStyle(
fontSize: 16,
color: AppColors.textPrimary,
),
),
),
],
),
);
}
/// 选择图片
Future<void> _pickImage(ReportCubit cubit) async {
final ImagePicker picker = ImagePicker();
try {
final XFile? image = await picker.pickImage(
source: ImageSource.camera,
maxWidth: 1920,
maxHeight: 1080,
imageQuality: 85,
);
if (image != null) {
cubit.addMediaFile(image.path);
}
} catch (e) {
debugPrint('拍照失败: $e');
}
}
/// 选择视频
Future<void> _pickVideo(ReportCubit cubit) async {
final ImagePicker picker = ImagePicker();
try {
final XFile? video = await picker.pickVideo(
source: ImageSource.camera,
maxDuration: const Duration(minutes: 5),
);
if (video != null) {
cubit.addMediaFile(video.path);
}
} catch (e) {
debugPrint('录像失败: $e');
}
}
/// 预览媒体文件
void _previewMedia(BuildContext context, List<String> mediaFiles, int index) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MediaPreviewPage(
mediaFiles: mediaFiles,
initialIndex: index,
),
),
);
}
/// 从相册选择
Future<void> _pickFromGallery(BuildContext context, ReportCubit cubit) async {
final ImagePicker picker = ImagePicker();
try {
// 显示选择图片或视频的选项
await showModalBottomSheet(
context: context,
builder: (context) => SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.image),
title: const Text('选择图片'),
onTap: () async {
Navigator.pop(context);
final XFile? image = await picker.pickImage(
source: ImageSource.gallery,
maxWidth: 1920,
maxHeight: 1080,
imageQuality: 85,
);
if (image != null) {
cubit.addMediaFile(image.path);
}
},
),
ListTile(
leading: const Icon(Icons.video_library),
title: const Text('选择视频'),
onTap: () async {
Navigator.pop(context);
final XFile? video = await picker.pickVideo(
source: ImageSource.gallery,
);
if (video != null) {
cubit.addMediaFile(video.path);
}
},
),
],
),
),
);
} catch (e) {
debugPrint('从相册选择失败: $e');
}
}
/// 显示位置选择器
void _showLocationPicker(BuildContext context, ReportCubit cubit) {
final locations = [
'主厂房A区',
'主厂房B区',
'锅炉房',
'汽机房',
'控制室',
'配电室',
];
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('选择位置'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: locations.map((location) {
return ListTile(
title: Text(location),
onTap: () {
cubit.updateLocation(location);
Navigator.pop(context);
},
);
}).toList(),
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消'),
),
],
),
);
}
/// 显示设备选择器
void _showDevicePicker(BuildContext context, ReportCubit cubit) {
final devices = [
'锅炉1号',
'锅炉2号',
'汽轮机1号',
'发电机1号',
'变压器1号',
'水泵1号',
];
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('选择设备'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: devices.map((device) {
return ListTile(
title: Text(device),
onTap: () {
cubit.selectDevice(device);
Navigator.pop(context);
},
);
}).toList(),
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消'),
),
],
),
);
}
/// 显示成功对话框
void _showSuccessDialog(BuildContext context) {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: const Text('提交成功'),
content: const Text('您的上报已成功提交'),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
Navigator.pop(context); // 返回上一页
},
child: const Text('确定'),
),
],
),
);
}
/// 显示错误对话框
void _showErrorDialog(BuildContext context, String message) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('提交失败'),
content: Text(message),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('确定'),
),
],
),
);
}
}