所有一级页面和不分二级页面
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 全局颜色常量
|
||||
class AppColors {
|
||||
static const Color primary = Color(0xFF165DFF);
|
||||
static const Color danger = Color(0xFFF53F3F);
|
||||
static const Color warning = Color(0xFFFF7D00);
|
||||
static const Color textPrimary = Color(0xFF1D2129);
|
||||
static const Color textSecondary = Color(0xFF4E5969);
|
||||
static const Color textHint = Color(0xFF86909C);
|
||||
static const Color background = Color(0xFFFFFFFF);
|
||||
static const Color cardBackground = Color(0xFFF8F9FA);
|
||||
static const Color borderColor = Color(0xFFE5E6EB);
|
||||
}
|
||||
|
||||
/// 全局尺寸常量
|
||||
class AppDimensions {
|
||||
static const double borderRadius = 16.0;
|
||||
static const double borderRadiusSmall = 8.0;
|
||||
static const double borderRadiusMedium = 12.0;
|
||||
static const double horizontalPadding = 16.0;
|
||||
static const double moduleSpacing = 20.0;
|
||||
static const double cardShadowBlur = 4.0;
|
||||
static const double buttonHeight = 48.0;
|
||||
static const double appBarHeight = 44.0;
|
||||
}
|
||||
|
||||
/// 上报类型枚举
|
||||
enum ReportType {
|
||||
deviceFault('设备故障', Icons.notifications_active),
|
||||
patrolRecord('巡检记录', Icons.description),
|
||||
hiddenDanger('隐患上报', Icons.shield),
|
||||
defectReport('缺陷上报', Icons.build);
|
||||
|
||||
final String label;
|
||||
final IconData icon;
|
||||
|
||||
const ReportType(this.label, this.icon);
|
||||
}
|
||||
|
||||
/// 问题等级枚举
|
||||
enum ProblemLevel {
|
||||
normal('一般', Color(0xFF86909C), Color(0xFFE5E6EB)),
|
||||
important('重要', Color(0xFFFF7D00), Color(0xFFE5E6EB)),
|
||||
urgent('紧急', Color(0xFFF53F3F), Color(0xFFF53F3F));
|
||||
|
||||
final String label;
|
||||
final Color textColor;
|
||||
final Color borderColor;
|
||||
|
||||
const ProblemLevel(this.label, this.textColor, this.borderColor);
|
||||
}
|
||||
137
lib/features/v2/report/presentation/cubit/report_cubit.dart
Normal file
137
lib/features/v2/report/presentation/cubit/report_cubit.dart
Normal file
@@ -0,0 +1,137 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../domain/entities/report_entity.dart';
|
||||
import '../../domain/usecases/submit_report_usecase.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
import '../states/report_state.dart';
|
||||
|
||||
/// 上报页面 Cubit
|
||||
class ReportCubit extends Cubit<ReportState> {
|
||||
final SubmitReportUseCase submitReportUseCase;
|
||||
|
||||
ReportCubit({required this.submitReportUseCase})
|
||||
: super(ReportFormState(report: ReportEntity()));
|
||||
|
||||
/// 选择上报类型
|
||||
void selectReportType(ReportType type) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
emit(currentState.copyWith(
|
||||
selectedReportType: type,
|
||||
report: currentState.report.copyWith(
|
||||
reportType: type.label,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 选择设备
|
||||
void selectDevice(String device) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
emit(currentState.copyWith(
|
||||
selectedDevice: device,
|
||||
report: currentState.report.copyWith(deviceId: device),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 更新位置
|
||||
void updateLocation(String location) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
emit(currentState.copyWith(
|
||||
location: location,
|
||||
report: currentState.report.copyWith(location: location),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 更新问题描述
|
||||
void updateDescription(String description) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
emit(currentState.copyWith(
|
||||
report: currentState.report.copyWith(description: description),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 选择问题等级
|
||||
void selectProblemLevel(ProblemLevel level) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
emit(currentState.copyWith(
|
||||
selectedProblemLevel: level,
|
||||
report: currentState.report.copyWith(
|
||||
problemLevel: level.label,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 添加媒体文件
|
||||
void addMediaFile(String filePath) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
final updatedFiles = List<String>.from(currentState.mediaFiles)
|
||||
..add(filePath);
|
||||
emit(currentState.copyWith(
|
||||
mediaFiles: updatedFiles,
|
||||
report: currentState.report.copyWith(mediaUrls: updatedFiles),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 删除媒体文件
|
||||
void removeMediaFile(int index) {
|
||||
if (state is ReportFormState) {
|
||||
final currentState = state as ReportFormState;
|
||||
final updatedFiles = List<String>.from(currentState.mediaFiles)
|
||||
..removeAt(index);
|
||||
emit(currentState.copyWith(
|
||||
mediaFiles: updatedFiles,
|
||||
report: currentState.report.copyWith(mediaUrls: updatedFiles),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// 提交上报
|
||||
Future<void> submitReport() async {
|
||||
if (state is! ReportFormState) return;
|
||||
|
||||
final currentState = state as ReportFormState;
|
||||
|
||||
// 验证必填项
|
||||
if (currentState.selectedDevice == null ||
|
||||
currentState.selectedDevice!.isEmpty) {
|
||||
emit(const ReportFailure('请选择设备'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentState.report.description == null ||
|
||||
currentState.report.description!.isEmpty) {
|
||||
emit(const ReportFailure('请填写问题描述'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentState.selectedProblemLevel == null) {
|
||||
emit(const ReportFailure('请选择问题等级'));
|
||||
return;
|
||||
}
|
||||
|
||||
// 开始提交
|
||||
emit(ReportSubmitting());
|
||||
|
||||
final result = await submitReportUseCase.execute(currentState.report);
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(ReportFailure(failure.message)),
|
||||
(success) => emit(ReportSuccess()),
|
||||
);
|
||||
}
|
||||
|
||||
/// 重置表单
|
||||
void resetForm() {
|
||||
emit(ReportFormState(report: ReportEntity()));
|
||||
}
|
||||
}
|
||||
@@ -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!),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
476
lib/features/v2/report/presentation/pages/report_page.dart
Normal file
476
lib/features/v2/report/presentation/pages/report_page.dart
Normal 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('确定'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
80
lib/features/v2/report/presentation/states/report_state.dart
Normal file
80
lib/features/v2/report/presentation/states/report_state.dart
Normal file
@@ -0,0 +1,80 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../domain/entities/report_entity.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
|
||||
/// 上报页面状态抽象类
|
||||
abstract class ReportState extends Equatable {
|
||||
const ReportState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
/// 初始状态
|
||||
class ReportInitial extends ReportState {}
|
||||
|
||||
/// 加载中状态
|
||||
class ReportLoading extends ReportState {}
|
||||
|
||||
/// 提交中状态
|
||||
class ReportSubmitting extends ReportState {}
|
||||
|
||||
/// 提交成功状态
|
||||
class ReportSuccess extends ReportState {}
|
||||
|
||||
/// 提交失败状态
|
||||
class ReportFailure extends ReportState {
|
||||
final String message;
|
||||
|
||||
const ReportFailure(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
/// 表单数据状态
|
||||
class ReportFormState extends ReportState {
|
||||
final ReportEntity report;
|
||||
final ReportType? selectedReportType;
|
||||
final ProblemLevel? selectedProblemLevel;
|
||||
final String location;
|
||||
final String? selectedDevice;
|
||||
final List<String> mediaFiles;
|
||||
|
||||
const ReportFormState({
|
||||
required this.report,
|
||||
this.selectedReportType,
|
||||
this.selectedProblemLevel,
|
||||
this.location = '江苏省苏州市吴中区',
|
||||
this.selectedDevice,
|
||||
this.mediaFiles = const [],
|
||||
});
|
||||
|
||||
ReportFormState copyWith({
|
||||
ReportEntity? report,
|
||||
ReportType? selectedReportType,
|
||||
ProblemLevel? selectedProblemLevel,
|
||||
String? location,
|
||||
String? selectedDevice,
|
||||
List<String>? mediaFiles,
|
||||
}) {
|
||||
return ReportFormState(
|
||||
report: report ?? this.report,
|
||||
selectedReportType: selectedReportType ?? this.selectedReportType,
|
||||
selectedProblemLevel: selectedProblemLevel ?? this.selectedProblemLevel,
|
||||
location: location ?? this.location,
|
||||
selectedDevice: selectedDevice ?? this.selectedDevice,
|
||||
mediaFiles: mediaFiles ?? this.mediaFiles,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
report,
|
||||
selectedReportType,
|
||||
selectedProblemLevel,
|
||||
location,
|
||||
selectedDevice,
|
||||
mediaFiles,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
|
||||
/// 问题描述输入模块
|
||||
class DescriptionInput extends StatelessWidget {
|
||||
final String? description;
|
||||
final Function(String) onChanged;
|
||||
|
||||
const DescriptionInput({
|
||||
super.key,
|
||||
this.description,
|
||||
required this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.all(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: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'问题描述',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
maxLines: 5,
|
||||
maxLength: 200,
|
||||
onChanged: onChanged,
|
||||
decoration: InputDecoration(
|
||||
hintText: '请详细描述问题现象...',
|
||||
hintStyle: TextStyle(color: AppColors.textHint),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
borderSide: BorderSide(color: AppColors.borderColor),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
borderSide: BorderSide(color: AppColors.borderColor),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
borderSide: BorderSide(color: AppColors.primary, width: 2),
|
||||
),
|
||||
counterText: '',
|
||||
),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'${description?.length ?? 0}/200',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textHint,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
|
||||
/// 设备选择器
|
||||
class DeviceSelector extends StatelessWidget {
|
||||
final String? selectedDevice;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const DeviceSelector({
|
||||
super.key,
|
||||
this.selectedDevice,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.all(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(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'设备选择',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
selectedDevice ?? '请选择设备',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: selectedDevice != null
|
||||
? AppColors.textPrimary
|
||||
: AppColors.textHint,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
Icons.arrow_drop_down,
|
||||
size: 20,
|
||||
color: AppColors.textHint,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
|
||||
/// 问题等级选择器
|
||||
class LevelSelector extends StatelessWidget {
|
||||
final ProblemLevel? selectedLevel;
|
||||
final Function(ProblemLevel) onSelected;
|
||||
|
||||
const LevelSelector({
|
||||
super.key,
|
||||
this.selectedLevel,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.all(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: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'问题等级',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: ProblemLevel.values.map((level) {
|
||||
final isSelected = selectedLevel == level;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => onSelected(level),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
height: AppDimensions.buttonHeight,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected && level == ProblemLevel.urgent
|
||||
? AppColors.danger.withOpacity(0.1)
|
||||
: AppColors.background,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
border: Border.all(
|
||||
color: isSelected ? level.borderColor : AppColors.borderColor,
|
||||
width: isSelected ? 2 : 1,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
level.label,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: isSelected ? level.textColor : level.textColor.withOpacity(0.6),
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
259
lib/features/v2/report/presentation/widgets/media_uploader.dart
Normal file
259
lib/features/v2/report/presentation/widgets/media_uploader.dart
Normal file
@@ -0,0 +1,259 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
|
||||
/// 媒体上传模块
|
||||
class MediaUploader extends StatelessWidget {
|
||||
final List<String> mediaFiles;
|
||||
final VoidCallback onCameraTap;
|
||||
final VoidCallback onVideoTap;
|
||||
final VoidCallback onAddFromGallery;
|
||||
final Function(int) onRemove;
|
||||
final Function(int)? onTap;
|
||||
|
||||
const MediaUploader({
|
||||
super.key,
|
||||
required this.mediaFiles,
|
||||
required this.onCameraTap,
|
||||
required this.onVideoTap,
|
||||
required this.onAddFromGallery,
|
||||
required this.onRemove,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.all(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: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'上传图片/视频',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
// 拍照按钮
|
||||
_buildUploadButton(
|
||||
icon: Icons.camera_alt,
|
||||
label: '拍照',
|
||||
onTap: onCameraTap,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// 录像按钮
|
||||
_buildUploadButton(
|
||||
icon: Icons.videocam,
|
||||
label: '录像',
|
||||
onTap: onVideoTap,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// 已上传的媒体预览
|
||||
...mediaFiles.asMap().entries.map((entry) {
|
||||
final String filePath = entry.value;
|
||||
final bool isNetworkImage = filePath.startsWith('http');
|
||||
final bool isVideo = _isVideoFile(filePath);
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => onTap?.call(entry.key),
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
margin: const EdgeInsets.only(right: 8),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
color: AppColors.cardBackground,
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
child: isVideo
|
||||
? _buildVideoThumbnail(filePath)
|
||||
: (isNetworkImage
|
||||
? Image.network(
|
||||
filePath,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return _buildPlaceholderIcon(Icons.broken_image);
|
||||
},
|
||||
)
|
||||
: Image.file(
|
||||
File(filePath),
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return _buildPlaceholderIcon(Icons.broken_image);
|
||||
},
|
||||
)),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 4,
|
||||
right: 12,
|
||||
child: GestureDetector(
|
||||
onTap: () => onRemove(entry.key),
|
||||
child: Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black54,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.close,
|
||||
size: 14,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// 视频播放图标
|
||||
if (isVideo)
|
||||
Positioned(
|
||||
child: Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
margin: const EdgeInsets.only(right: 8),
|
||||
alignment: Alignment.center,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black38,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.play_arrow,
|
||||
color: Colors.white,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
// 添加按钮
|
||||
_buildUploadButton(
|
||||
icon: Icons.add,
|
||||
label: '',
|
||||
onTap: onAddFromGallery,
|
||||
isAddButton: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUploadButton({
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required VoidCallback onTap,
|
||||
bool isAddButton = false,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
color: isAddButton ? AppColors.cardBackground : AppColors.background,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusMedium),
|
||||
border: Border.all(
|
||||
color: isAddButton ? AppColors.borderColor : AppColors.primary,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
color: isAddButton ? AppColors.textHint : AppColors.primary,
|
||||
size: 24,
|
||||
),
|
||||
if (label.isNotEmpty) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isAddButton ? AppColors.textHint : AppColors.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 判断是否为视频文件
|
||||
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');
|
||||
}
|
||||
|
||||
/// 构建视频缩略图(显示占位符)
|
||||
Widget _buildVideoThumbnail(String filePath) {
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// 灰色背景
|
||||
Container(
|
||||
color: Colors.grey[300],
|
||||
),
|
||||
// 视频图标
|
||||
const Center(
|
||||
child: Icon(
|
||||
Icons.videocam,
|
||||
color: Colors.grey,
|
||||
size: 32,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建占位图标
|
||||
Widget _buildPlaceholderIcon(IconData icon) {
|
||||
return Container(
|
||||
color: Colors.grey[300],
|
||||
child: Center(
|
||||
child: Icon(
|
||||
icon,
|
||||
color: Colors.grey,
|
||||
size: 32,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../constants/report_constants.dart';
|
||||
|
||||
/// 上报类型选择器
|
||||
class ReportTypeSelector extends StatelessWidget {
|
||||
final ReportType? selectedType;
|
||||
final Function(ReportType) onSelected;
|
||||
|
||||
const ReportTypeSelector({
|
||||
super.key,
|
||||
this.selectedType,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppDimensions.horizontalPadding),
|
||||
child: Row(
|
||||
children: ReportType.values.map((type) {
|
||||
final isSelected = selectedType == type;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => onSelected(type),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.background,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
border: Border.all(
|
||||
color: isSelected ? AppColors.primary : AppColors.borderColor,
|
||||
width: isSelected ? 2 : 1,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0x0D000000),
|
||||
blurRadius: AppDimensions.cardShadowBlur,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
type.icon,
|
||||
color: isSelected ? AppColors.primary : AppColors.textHint,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
type.label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isSelected ? AppColors.primary : AppColors.textSecondary,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user