116 lines
4.1 KiB
Dart
116 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:intl/intl.dart';
|
|
import '../blocs/project/project_bloc.dart';
|
|
import '../blocs/project/project_event.dart';
|
|
import '../blocs/project/project_state.dart';
|
|
import '../models/project.dart';
|
|
|
|
class ProjectListPage extends StatelessWidget {
|
|
const ProjectListPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('历史项目'),
|
|
elevation: 0,
|
|
),
|
|
body: BlocBuilder<ProjectBloc, ProjectState>(
|
|
builder: (context, state) {
|
|
if (state is ProjectLoading) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
if (state is ProjectError) {
|
|
return Center(child: Text('Error: ${state.message}'));
|
|
}
|
|
if (state is ProjectLoaded) {
|
|
final projects = state.projects;
|
|
if (projects.isEmpty) {
|
|
return const Center(
|
|
child: Text('暂无历史项目'),
|
|
);
|
|
}
|
|
|
|
return ListView.builder(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: projects.length,
|
|
itemBuilder: (context, index) {
|
|
final project = projects[index];
|
|
|
|
final total = project.transcription.segments.length;
|
|
final translated = project.transcription.segments
|
|
.where((s) => s.translatedText?.isNotEmpty == true)
|
|
.length;
|
|
|
|
final dateFormat = DateFormat('yyyy-MM-dd HH:mm');
|
|
|
|
return Card(
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
child: ListTile(
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
title: Text(
|
|
project.name,
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
subtitle: Padding(
|
|
padding: const EdgeInsets.only(top: 8.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text('最后更新: ${dateFormat.format(project.updatedAt)}'),
|
|
const SizedBox(height: 4),
|
|
Text('翻译进度: $translated / $total',
|
|
style: TextStyle(
|
|
color: translated == total && total > 0
|
|
? Colors.green
|
|
: Theme.of(context).colorScheme.primary,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
trailing: IconButton(
|
|
icon: const Icon(Icons.delete_outline, color: Colors.red),
|
|
onPressed: () => _confirmDelete(context, project),
|
|
),
|
|
onTap: () {
|
|
Navigator.of(context).pop(project);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
return const SizedBox.shrink();
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
void _confirmDelete(BuildContext context, Project project) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
title: const Text('删除项目'),
|
|
content: Text('确定要删除《${project.name}》吗?此操作无法恢复。'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(ctx).pop(),
|
|
child: const Text('取消'),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(ctx).pop();
|
|
context.read<ProjectBloc>().add(DeleteProject(project.id));
|
|
},
|
|
child: const Text('删除', style: TextStyle(color: Colors.red)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|