Files
2026-09-23 15:33:59 +08:00

49 lines
1.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../providers/note_provider.dart';
/// 首页仪表盘上「笔记」卡片的摘要:笔记总数 + 最近更新时间。
///
/// 数据来自 [noteOverviewProvider](只取 1 条),不碰列表页那套状态。
class NoteModuleSummary extends ConsumerWidget {
const NoteModuleSummary({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final page = ref.watch(noteOverviewProvider).value;
final latest = (page == null || page.items.isEmpty)
? null
: page.items.first.updateTime;
return Row(
children: [
Expanded(child: _item('共', page == null ? null : '${page.total} 篇')),
Expanded(child: _item('最近更新', latest == null ? null : _shortDate(latest))),
],
);
}
/// 后端给的是 `yyyy-MM-dd HH:mm`,卡片上只要 `MM-dd`
String _shortDate(String value) =>
value.length >= 10 ? value.substring(5, 10) : value;
Widget _item(String label, String? value) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: const TextStyle(fontSize: 11, color: Color(0xFF8D6E63))),
const SizedBox(height: 3),
Text(
value ?? '--',
style: const TextStyle(
fontSize: 14.5,
fontWeight: FontWeight.bold,
color: Color(0xFF5D4037),
),
),
],
);
}
}