99 lines
2.8 KiB
Dart
99 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../models/record.dart';
|
|
import '../data/categories.dart';
|
|
|
|
class RecordDetailDialog extends StatelessWidget {
|
|
final Record record;
|
|
final VoidCallback onEdit;
|
|
final VoidCallback onDelete;
|
|
|
|
const RecordDetailDialog({
|
|
Key? key,
|
|
required this.record,
|
|
required this.onEdit,
|
|
required this.onDelete,
|
|
}) : super(key: key);
|
|
|
|
/// 获取分类信息
|
|
Category _getCategory(String categoryId, RecordType type) {
|
|
return CategoryConfig.getCategoriesByType(type)
|
|
.firstWhere((c) => c.id == categoryId);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final category = _getCategory(record.categoryId, record.type);
|
|
|
|
return AlertDialog(
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
const Text('记录详情'),
|
|
Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
IconButton(
|
|
icon: const Icon(Icons.edit),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
onEdit();
|
|
},
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.delete),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
onDelete();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
ListTile(
|
|
title: const Text('分类'),
|
|
subtitle: Text(category.name),
|
|
leading: Icon(category.icon),
|
|
onTap: () {
|
|
// TODO: 跳转到分类详情页
|
|
},
|
|
),
|
|
if (record.note != null)
|
|
ListTile(
|
|
title: const Text('备注'),
|
|
subtitle: Text(record.note!),
|
|
),
|
|
ListTile(
|
|
title: const Text('金额'),
|
|
subtitle: Text(
|
|
'${record.type == RecordType.expense ? "-" : "+"}¥${record.amount.toStringAsFixed(2)}',
|
|
style: TextStyle(
|
|
color: record.type == RecordType.expense
|
|
? Colors.red
|
|
: Colors.green,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
ListTile(
|
|
title: const Text('时间'),
|
|
subtitle: Text(
|
|
'${record.createTime.year}-${record.createTime.month}-${record.createTime.day} '
|
|
'${record.createTime.hour}:${record.createTime.minute}',
|
|
),
|
|
),
|
|
ListTile(
|
|
title: const Text('账户'),
|
|
subtitle: const Text('默认账户'),
|
|
onTap: () {
|
|
// TODO: 跳转到账户页
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
} |