Initial project import
This commit is contained in:
@@ -0,0 +1,972 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:miaoji_zhang/shared/api/api_client.dart';
|
||||
import 'package:miaoji_zhang/shared/api/business_api.dart';
|
||||
import 'package:miaoji_zhang/shared/api/config_api.dart';
|
||||
import 'package:miaoji_zhang/shared/services/current_ledger_store.dart';
|
||||
import 'package:miaoji_zhang/shared/services/session_store.dart';
|
||||
import 'package:miaoji_zhang/shared/services/transaction_events.dart';
|
||||
import 'package:miaoji_zhang/shared/theme/app_theme.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/category_icon.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/app_icons.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/async_error_view.dart';
|
||||
import 'package:miaoji_zhang/features/home/pages/tx_detail_page.dart';
|
||||
import 'package:miaoji_zhang/features/home/pages/ledger_sheet.dart';
|
||||
import 'package:miaoji_zhang/shared/services/shanghai_time.dart';
|
||||
|
||||
/// 首页明细(P1 / P20 空状态)
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
|
||||
@override
|
||||
State<HomePage> createState() => HomePageState();
|
||||
}
|
||||
|
||||
class HomePageState extends State<HomePage> {
|
||||
MonthSummary? _summary;
|
||||
BudgetsData? _budgets;
|
||||
bool _loading = true;
|
||||
String? _error;
|
||||
late DateTime _month;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_month = ShanghaiTime.now;
|
||||
PublicConfigApi.companionNotifier.addListener(_refreshCompanion);
|
||||
TransactionEvents.revision.addListener(_refreshTransactions);
|
||||
CurrentLedgerStore.instance.addListener(_refreshLedger);
|
||||
refresh();
|
||||
}
|
||||
|
||||
void _refreshCompanion() {
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
void _refreshTransactions() {
|
||||
if (mounted) refresh();
|
||||
}
|
||||
|
||||
void _refreshLedger() {
|
||||
if (mounted) refresh();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
PublicConfigApi.companionNotifier.removeListener(_refreshCompanion);
|
||||
TransactionEvents.revision.removeListener(_refreshTransactions);
|
||||
CurrentLedgerStore.instance.removeListener(_refreshLedger);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
setState(() {
|
||||
_loading = true;
|
||||
_error = null;
|
||||
});
|
||||
try {
|
||||
await CurrentLedgerStore.instance.ensureLoaded();
|
||||
final results = await Future.wait<dynamic>([
|
||||
TxApi.month(_month.year, _month.month),
|
||||
BudgetApi.get(_month.year, _month.month),
|
||||
]);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_summary = results[0] as MonthSummary;
|
||||
_budgets = results[1] as BudgetsData;
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
try {
|
||||
final summary = await TxApi.month(_month.year, _month.month);
|
||||
if (mounted) setState(() => _summary = summary);
|
||||
} catch (fallbackError) {
|
||||
if (mounted) {
|
||||
setState(() => _error = apiErrorMessage(fallbackError));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = _summary;
|
||||
final budgets = _budgets;
|
||||
final session = SessionStore.instance;
|
||||
final showAiEntry = session.isGuest || session.aiEnabled;
|
||||
final budgetsByCategory = <int, BudgetItem>{
|
||||
for (final item in budgets?.categories ?? const <BudgetItem>[])
|
||||
if (item.categoryId != null) item.categoryId!: item,
|
||||
};
|
||||
if (!_loading && s == null && _error != null) {
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: AsyncErrorView(message: _error!, onRetry: refresh),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: refresh,
|
||||
color: AppTheme.primary,
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (notification) {
|
||||
if (notification is ScrollStartNotification) {
|
||||
_SwipeReveal.closeOpen();
|
||||
}
|
||||
return false;
|
||||
},
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
children: [
|
||||
SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
_month = DateTime(_month.year, _month.month - 1);
|
||||
refresh();
|
||||
},
|
||||
child: Transform(
|
||||
alignment: Alignment.center,
|
||||
transform: Matrix4.rotationY(3.1416),
|
||||
child: AppIcons.icon(
|
||||
AppIcons.chevronRight,
|
||||
size: 16,
|
||||
color: context.jz.text3,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 6),
|
||||
GestureDetector(
|
||||
onTap: () =>
|
||||
LedgerSheet.show(context).then((_) => refresh()),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
CurrentLedgerStore.instance.currentName,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
AppIcons.icon(
|
||||
AppIcons.chevronDown,
|
||||
size: 16,
|
||||
color: context.jz.text3,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(width: 6),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
_month = DateTime(_month.year, _month.month + 1);
|
||||
refresh();
|
||||
},
|
||||
child: AppIcons.icon(
|
||||
AppIcons.chevronRight,
|
||||
size: 16,
|
||||
color: context.jz.text3,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
IconButton(
|
||||
icon: AppIcons.icon(
|
||||
AppIcons.search,
|
||||
size: 20,
|
||||
color: context.jz.text2,
|
||||
),
|
||||
onPressed: () => context.push('/search'),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
'${_month.year}年${_month.month}月',
|
||||
style: TextStyle(fontSize: 11, color: context.jz.text3),
|
||||
),
|
||||
SizedBox(height: 6),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primary,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${_month.month}月结余',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white.withValues(alpha: 0.85),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
Text(
|
||||
'¥ ${(s?.balance ?? 0).toStringAsFixed(2)}',
|
||||
style: TextStyle(
|
||||
fontSize: 30,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 14),
|
||||
Row(
|
||||
children: [
|
||||
_HeroCol(label: '收入', value: s?.income ?? 0),
|
||||
_HeroCol(label: '支出', value: s?.expense ?? 0),
|
||||
_HeroCol(
|
||||
label: '笔数',
|
||||
value: (s?.count ?? 0).toDouble(),
|
||||
isCount: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
if (budgets != null) ...[
|
||||
_BudgetSummaryCard(
|
||||
data: budgets,
|
||||
onTap: () async {
|
||||
await context.push('/budget');
|
||||
refresh();
|
||||
},
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
],
|
||||
if (showAiEntry) ...[
|
||||
GestureDetector(
|
||||
onTap: () => context.go('/chat'),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 13,
|
||||
vertical: 11,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: context.jz.card,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: context.jz.line, width: 0.5),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 19,
|
||||
backgroundColor: AppTheme.ai,
|
||||
child: AppIcons.icon(
|
||||
AppIcons.avatarAsset(
|
||||
PublicConfigApi.companionAvatarKey,
|
||||
),
|
||||
size: 20,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 11),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
PublicConfigApi.companionName,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
SessionStore.instance.shouldUseLocalOnly
|
||||
? '登录并连接云端后可使用 AI 记账'
|
||||
: '说句话就能记账',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: context.jz.text2,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 6,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: context.jz.aiBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Text(
|
||||
'去聊天',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppTheme.ai,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 15),
|
||||
],
|
||||
if (_loading && s == null)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 60),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: AppTheme.primary,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
)
|
||||
else if (s == null || s.days.isEmpty)
|
||||
_EmptyState(
|
||||
aiEnabled: showAiEntry,
|
||||
onAction: showAiEntry
|
||||
? () => context.go('/chat')
|
||||
: () => context.push('/add'),
|
||||
companionName: PublicConfigApi.companionName,
|
||||
avatarKey: PublicConfigApi.companionAvatarKey,
|
||||
)
|
||||
else ...[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 2, bottom: 9),
|
||||
child: Text(
|
||||
'最近账单',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
...s.days.map(
|
||||
(d) => _DayCard(
|
||||
day: d,
|
||||
onDeleted: refresh,
|
||||
budgetsByCategory: budgetsByCategory,
|
||||
),
|
||||
),
|
||||
],
|
||||
SizedBox(height: 12),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _BudgetSummaryCard extends StatelessWidget {
|
||||
final BudgetsData data;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _BudgetSummaryCard({required this.data, required this.onTap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final total = data.total;
|
||||
final amount =
|
||||
total?.amount ??
|
||||
data.categories.fold<double>(0, (sum, item) => sum + item.amount);
|
||||
final spent =
|
||||
total?.spent ??
|
||||
data.categories.fold<double>(0, (sum, item) => sum + item.spent);
|
||||
final rawRatio = amount <= 0 ? 0.0 : spent / amount;
|
||||
final ratio = rawRatio.clamp(0.0, 1.0);
|
||||
final warningColor = rawRatio >= 1
|
||||
? AppTheme.red
|
||||
: rawRatio >= 0.8
|
||||
? AppTheme.orange
|
||||
: AppTheme.primary;
|
||||
|
||||
return Material(
|
||||
color: context.jz.card,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: context.jz.line, width: 0.5),
|
||||
),
|
||||
child: amount <= 0
|
||||
? Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.donut_small_rounded,
|
||||
size: 22,
|
||||
color: AppTheme.primary,
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'本月预算',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'设一个可执行的消费边界',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: context.jz.text3,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'去设置',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppTheme.primary,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
total?.isRecurring == true ? '周期预算' : '本月预算',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Text(
|
||||
rawRatio >= 1
|
||||
? '已超 ¥${(spent - amount).toStringAsFixed(0)}'
|
||||
: '剩余 ¥${(amount - spent).toStringAsFixed(0)}',
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: warningColor,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 9),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
child: LinearProgressIndicator(
|
||||
value: ratio,
|
||||
minHeight: 6,
|
||||
backgroundColor: context.jz.line,
|
||||
color: warningColor,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 7),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'已用 ¥${spent.toStringAsFixed(0)}',
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
color: context.jz.text3,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Text(
|
||||
'预算 ¥${amount.toStringAsFixed(0)} · ${(rawRatio * 100).toStringAsFixed(0)}%',
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
color: context.jz.text3,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _HeroCol extends StatelessWidget {
|
||||
final String label;
|
||||
final double value;
|
||||
final bool isCount;
|
||||
const _HeroCol({
|
||||
required this.label,
|
||||
required this.value,
|
||||
this.isCount = false,
|
||||
});
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: Colors.white.withValues(alpha: 0.85),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 2),
|
||||
Text(
|
||||
isCount
|
||||
? value.toInt().toString()
|
||||
: '¥ ${value.toStringAsFixed(2)}',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _EmptyState extends StatelessWidget {
|
||||
final VoidCallback onAction;
|
||||
final String companionName, avatarKey;
|
||||
final bool aiEnabled;
|
||||
|
||||
const _EmptyState({
|
||||
required this.onAction,
|
||||
required this.aiEnabled,
|
||||
required this.companionName,
|
||||
required this.avatarKey,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 40),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 100,
|
||||
height: 100,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: aiEnabled
|
||||
? context.jz.aiBackground
|
||||
: context.jz.primaryBackground,
|
||||
),
|
||||
child: AppIcons.icon(
|
||||
aiEnabled ? AppIcons.avatarAsset(avatarKey) : AppIcons.wallet,
|
||||
size: 48,
|
||||
color: aiEnabled ? AppTheme.ai : AppTheme.primary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'还没有账单',
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700),
|
||||
),
|
||||
SizedBox(height: 6),
|
||||
Text(
|
||||
aiEnabled
|
||||
? '跟我说句话就能记账,比如\n"早饭包子豆浆 6 块" · "打车 45"'
|
||||
: '点击下方按钮手动记录第一笔账单',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: context.jz.text2,
|
||||
height: 1.7,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 18),
|
||||
ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: aiEnabled ? AppTheme.ai : AppTheme.primary,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||
),
|
||||
onPressed: onAction,
|
||||
icon: AppIcons.icon(
|
||||
aiEnabled ? AppIcons.chat : AppIcons.plus,
|
||||
size: 16,
|
||||
color: Colors.white,
|
||||
),
|
||||
label: Text(aiEnabled ? '和${companionName}聊聊' : '记一笔'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DayCard extends StatelessWidget {
|
||||
final DayGroup day;
|
||||
final VoidCallback onDeleted;
|
||||
final Map<int, BudgetItem> budgetsByCategory;
|
||||
const _DayCard({
|
||||
required this.day,
|
||||
required this.onDeleted,
|
||||
required this.budgetsByCategory,
|
||||
});
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final now = ShanghaiTime.now;
|
||||
final isToday =
|
||||
day.date.year == now.year &&
|
||||
day.date.month == now.month &&
|
||||
day.date.day == now.day;
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: context.jz.card,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: context.jz.line, width: 0.5),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 9),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
isToday
|
||||
? '今天 · ${day.date.month}月${day.date.day}日'
|
||||
: '${day.date.month}月${day.date.day}日',
|
||||
style: TextStyle(fontSize: 11, color: context.jz.text3),
|
||||
),
|
||||
Spacer(),
|
||||
Text(
|
||||
[
|
||||
if (day.income > 0) '收 ¥${day.income.toStringAsFixed(2)}',
|
||||
if (day.expense > 0) '支 ¥${day.expense.toStringAsFixed(2)}',
|
||||
].join(' · '),
|
||||
style: TextStyle(fontSize: 11, color: context.jz.text3),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Divider(height: 0.5, color: context.jz.line),
|
||||
...day.items.map(
|
||||
(t) => _TxRow(
|
||||
tx: t,
|
||||
onDeleted: onDeleted,
|
||||
budget: budgetsByCategory[t.categoryId],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TxRow extends StatelessWidget {
|
||||
final TxItem tx;
|
||||
final VoidCallback onDeleted;
|
||||
final BudgetItem? budget;
|
||||
const _TxRow({required this.tx, required this.onDeleted, this.budget});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final hh =
|
||||
'${tx.occurredAt.hour.toString().padLeft(2, '0')}:${tx.occurredAt.minute.toString().padLeft(2, '0')}';
|
||||
return _SwipeReveal(
|
||||
id: tx.id,
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => TxDetailPage(tx: tx)),
|
||||
),
|
||||
onDelete: () async {
|
||||
try {
|
||||
await TxApi.delete(tx.id);
|
||||
onDeleted();
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context)
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(
|
||||
SnackBar(
|
||||
behavior: SnackBarBehavior.floating,
|
||||
content: Text('已移入回收站'),
|
||||
action: SnackBarAction(
|
||||
label: '撤销',
|
||||
textColor: AppTheme.primary,
|
||||
onPressed: () async {
|
||||
try {
|
||||
await TxApi.restore(tx.id);
|
||||
onDeleted();
|
||||
} catch (error) {
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(apiErrorMessage(error))),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(apiErrorMessage(error))));
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Row(
|
||||
children: [
|
||||
CategoryIconBox(
|
||||
iconKey: tx.categoryIcon,
|
||||
colorKey: tx.categoryColor,
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
tx.note ?? tx.categoryName,
|
||||
style: TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
SizedBox(height: 2),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
hh,
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
color: context.jz.text3,
|
||||
),
|
||||
),
|
||||
if (!tx.isIncome &&
|
||||
budget != null &&
|
||||
budget!.amount > 0 &&
|
||||
budget!.spent / budget!.amount >= 0.8) ...[
|
||||
SizedBox(width: 5),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 1.5,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: budget!.spent >= budget!.amount
|
||||
? context.jz.expenseBackground
|
||||
: context.jz.warningBackground,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
budget!.spent >= budget!.amount
|
||||
? '预算已超'
|
||||
: '预算 ${(budget!.spent / budget!.amount * 100).toStringAsFixed(0)}%',
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
color: budget!.spent >= budget!.amount
|
||||
? AppTheme.red
|
||||
: AppTheme.orange,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (tx.isAi) ...[
|
||||
SizedBox(width: 5),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 1.5,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: context.jz.aiBackground,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
'✦ AI',
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
color: AppTheme.ai,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${tx.isIncome ? '+' : '-'}${tx.amount.toStringAsFixed(2)}',
|
||||
style: TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: tx.isIncome ? AppTheme.primary : context.jz.text,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SwipeReveal extends StatefulWidget {
|
||||
static const double actionWidth = 76;
|
||||
static final ValueNotifier<int?> _openId = ValueNotifier<int?>(null);
|
||||
|
||||
final int id;
|
||||
final Widget child;
|
||||
final VoidCallback onTap;
|
||||
final Future<void> Function() onDelete;
|
||||
|
||||
const _SwipeReveal({
|
||||
required this.id,
|
||||
required this.child,
|
||||
required this.onTap,
|
||||
required this.onDelete,
|
||||
});
|
||||
|
||||
static void closeOpen() {
|
||||
_openId.value = null;
|
||||
}
|
||||
|
||||
@override
|
||||
State<_SwipeReveal> createState() => _SwipeRevealState();
|
||||
}
|
||||
|
||||
class _SwipeRevealState extends State<_SwipeReveal> {
|
||||
double _dragOffset = 0;
|
||||
bool _dragging = false;
|
||||
bool _deleting = false;
|
||||
|
||||
void _startDrag(DragStartDetails details) {
|
||||
_dragging = true;
|
||||
_dragOffset = _SwipeReveal._openId.value == widget.id
|
||||
? -_SwipeReveal.actionWidth
|
||||
: 0;
|
||||
if (_SwipeReveal._openId.value != widget.id) {
|
||||
_SwipeReveal.closeOpen();
|
||||
}
|
||||
}
|
||||
|
||||
void _updateDrag(DragUpdateDetails details) {
|
||||
setState(() {
|
||||
_dragOffset = (_dragOffset + details.delta.dx).clamp(
|
||||
-_SwipeReveal.actionWidth,
|
||||
0,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void _endDrag(DragEndDetails details) {
|
||||
final reveal =
|
||||
_dragOffset <= -36 ||
|
||||
(details.primaryVelocity != null && details.primaryVelocity! < -500);
|
||||
_dragging = false;
|
||||
_SwipeReveal._openId.value = reveal ? widget.id : null;
|
||||
setState(() => _dragOffset = reveal ? -_SwipeReveal.actionWidth : 0);
|
||||
}
|
||||
|
||||
Future<void> _delete() async {
|
||||
if (_deleting) return;
|
||||
setState(() => _deleting = true);
|
||||
_SwipeReveal.closeOpen();
|
||||
try {
|
||||
await widget.onDelete();
|
||||
} finally {
|
||||
if (mounted) setState(() => _deleting = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ValueListenableBuilder<int?>(
|
||||
valueListenable: _SwipeReveal._openId,
|
||||
builder: (_, openId, __) {
|
||||
final target = _dragging
|
||||
? _dragOffset
|
||||
: openId == widget.id
|
||||
? -_SwipeReveal.actionWidth
|
||||
: 0.0;
|
||||
return ClipRect(
|
||||
child: Stack(
|
||||
alignment: Alignment.centerRight,
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Semantics(
|
||||
button: true,
|
||||
label: '删除账单',
|
||||
child: Material(
|
||||
color: AppTheme.red,
|
||||
child: InkWell(
|
||||
onTap: _deleting ? null : _delete,
|
||||
child: SizedBox(
|
||||
width: _SwipeReveal.actionWidth,
|
||||
child: Center(
|
||||
child: _deleting
|
||||
? SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: AppIcons.icon(
|
||||
AppIcons.trash,
|
||||
size: 20,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
AnimatedContainer(
|
||||
duration: _dragging
|
||||
? Duration.zero
|
||||
: const Duration(milliseconds: 180),
|
||||
curve: Curves.easeOutCubic,
|
||||
transform: Matrix4.translationValues(target, 0, 0),
|
||||
color: context.jz.card,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: openId == widget.id
|
||||
? _SwipeReveal.closeOpen
|
||||
: widget.onTap,
|
||||
onHorizontalDragStart: _startDrag,
|
||||
onHorizontalDragUpdate: _updateDrag,
|
||||
onHorizontalDragEnd: _endDrag,
|
||||
onHorizontalDragCancel: () {
|
||||
_dragging = false;
|
||||
_SwipeReveal.closeOpen();
|
||||
},
|
||||
child: widget.child,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:miaoji_zhang/shared/api/api_client.dart';
|
||||
import 'package:miaoji_zhang/shared/services/current_ledger_store.dart';
|
||||
import 'package:miaoji_zhang/shared/theme/app_theme.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/app_icons.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/app_controls.dart';
|
||||
|
||||
/// P17 账本切换底部弹层
|
||||
class LedgerSheet extends StatefulWidget {
|
||||
const LedgerSheet({super.key});
|
||||
|
||||
@override
|
||||
State<LedgerSheet> createState() => _LedgerSheetState();
|
||||
|
||||
static Future<void> show(BuildContext context) => showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (_) => const LedgerSheet(),
|
||||
);
|
||||
}
|
||||
|
||||
class _LedgerSheetState extends State<LedgerSheet> {
|
||||
List<LedgerInfo> _ledgers = [];
|
||||
bool _loading = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
try {
|
||||
await CurrentLedgerStore.instance.ensureLoaded(force: true);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_ledgers = CurrentLedgerStore.instance.ledgers;
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
if (mounted) {
|
||||
setState(() => _loading = false);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(apiErrorMessage(error))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _setDefault(int id) async {
|
||||
try {
|
||||
await CurrentLedgerStore.instance.select(id);
|
||||
if (mounted) Navigator.pop(context, true);
|
||||
} catch (error) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(apiErrorMessage(error))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _create() async {
|
||||
final name = await showJzTextInputSheet(
|
||||
context,
|
||||
title: '新建账本',
|
||||
label: '账本名称',
|
||||
maxLength: 12,
|
||||
);
|
||||
if (name == null || name.isEmpty) return;
|
||||
try {
|
||||
await CurrentLedgerStore.instance.create(name);
|
||||
await _load();
|
||||
} catch (error) {
|
||||
if (mounted) _showError(error);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _rename(LedgerInfo ledger) async {
|
||||
final name = await showJzTextInputSheet(
|
||||
context,
|
||||
title: '重命名账本',
|
||||
label: '账本名称',
|
||||
initialValue: ledger.name,
|
||||
maxLength: 12,
|
||||
);
|
||||
if (name == null || name.isEmpty || name == ledger.name) return;
|
||||
try {
|
||||
await CurrentLedgerStore.instance.rename(ledger.id, name, ledger.iconKey);
|
||||
await _load();
|
||||
} catch (error) {
|
||||
if (mounted) _showError(error);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _delete(LedgerInfo ledger) async {
|
||||
final confirmed = await showJzConfirmSheet(
|
||||
context,
|
||||
title: '删除账本',
|
||||
message: '仅能删除没有账单和预算的非默认账本。',
|
||||
confirmLabel: '删除',
|
||||
destructive: true,
|
||||
);
|
||||
if (!confirmed) return;
|
||||
try {
|
||||
await CurrentLedgerStore.instance.delete(ledger.id);
|
||||
await _load();
|
||||
} catch (error) {
|
||||
if (mounted) _showError(error);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _showActions(LedgerInfo ledger) async {
|
||||
final action = await showJzOptionSheet<String>(
|
||||
context,
|
||||
title: ledger.name,
|
||||
options: [
|
||||
const JzOption(value: 'rename', label: '重命名'),
|
||||
if (!ledger.isDefault)
|
||||
const JzOption(value: 'delete', label: '删除账本', subtitle: '仅空账本可以删除'),
|
||||
],
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (action == 'rename') await _rename(ledger);
|
||||
if (action == 'delete') await _delete(ledger);
|
||||
}
|
||||
|
||||
void _showError(Object error) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(apiErrorMessage(error))));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: context.jz.card,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(22)),
|
||||
),
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).padding.bottom + 12,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 5,
|
||||
margin: const EdgeInsets.only(top: 10, bottom: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: context.jz.line,
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 8),
|
||||
child: Text(
|
||||
'切换账本',
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
if (_loading)
|
||||
Padding(
|
||||
padding: EdgeInsets.all(40),
|
||||
child: CircularProgressIndicator(
|
||||
color: AppTheme.primary,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
)
|
||||
else
|
||||
..._ledgers.map(
|
||||
(l) => Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 18,
|
||||
vertical: 4,
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: l.isDefault ? null : () => _setDefault(l.id),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(13),
|
||||
decoration: BoxDecoration(
|
||||
color: context.jz.card,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(
|
||||
color: l.isDefault ? AppTheme.primary : context.jz.line,
|
||||
width: l.isDefault ? 1.5 : 0.5,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 34,
|
||||
height: 34,
|
||||
decoration: BoxDecoration(
|
||||
color: l.isDefault
|
||||
? context.jz.primaryBackground
|
||||
: context.jz.background,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Center(
|
||||
child: AppIcons.byKey(
|
||||
l.iconKey,
|
||||
size: 17,
|
||||
color: l.isDefault
|
||||
? AppTheme.primary
|
||||
: context.jz.text3,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l.name,
|
||||
style: TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: l.isDefault
|
||||
? AppTheme.primary
|
||||
: context.jz.text,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${l.transactionCount} 笔',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: context.jz.text3,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (l.isDefault)
|
||||
AppIcons.icon(
|
||||
AppIcons.check,
|
||||
size: 18,
|
||||
color: AppTheme.primary,
|
||||
),
|
||||
IconButton(
|
||||
tooltip: '账本操作',
|
||||
onPressed: () => _showActions(l),
|
||||
icon: Icon(Icons.more_horiz_rounded, size: 19),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 4),
|
||||
child: InkWell(
|
||||
onTap: _create,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: context.jz.card,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: context.jz.line, width: 0.5),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
AppIcons.icon(
|
||||
AppIcons.plus,
|
||||
size: 14,
|
||||
color: context.jz.text2,
|
||||
),
|
||||
SizedBox(width: 6),
|
||||
Text(
|
||||
'新建账本',
|
||||
style: TextStyle(fontSize: 13, color: context.jz.text2),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:miaoji_zhang/shared/api/config_api.dart';
|
||||
import 'package:miaoji_zhang/shared/services/session_store.dart';
|
||||
import 'package:miaoji_zhang/shared/theme/app_theme.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/app_icons.dart';
|
||||
|
||||
class MainShell extends StatefulWidget {
|
||||
final StatefulNavigationShell shell;
|
||||
const MainShell({super.key, required this.shell});
|
||||
|
||||
@override
|
||||
State<MainShell> createState() => _MainShellState();
|
||||
}
|
||||
|
||||
class _MainShellState extends State<MainShell> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
PublicConfigApi.refreshCompanion();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: SessionStore.instance,
|
||||
builder: (context, _) {
|
||||
final session = SessionStore.instance;
|
||||
final aiEnabled = session.aiEnabled;
|
||||
final showAiEntry = session.isGuest || aiEnabled;
|
||||
if (!showAiEntry && widget.shell.currentIndex == 2) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) widget.shell.goBranch(0);
|
||||
});
|
||||
}
|
||||
return Scaffold(
|
||||
body: AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
switchInCurve: Curves.easeOut,
|
||||
switchOutCurve: Curves.easeIn,
|
||||
child: KeyedSubtree(
|
||||
key: ValueKey(widget.shell.currentIndex),
|
||||
child: widget.shell,
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: context.jz.card,
|
||||
border: Border(
|
||||
top: BorderSide(color: context.jz.line, width: 0.5),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: SizedBox(
|
||||
height: 64,
|
||||
child: Row(
|
||||
children: [
|
||||
_tab('明细', AppIcons.home, 0),
|
||||
_tab('统计', AppIcons.chart, 1),
|
||||
SizedBox(width: 72, child: _fab()),
|
||||
if (showAiEntry)
|
||||
ValueListenableBuilder<CompanionDisplay>(
|
||||
valueListenable: PublicConfigApi.companionNotifier,
|
||||
builder: (_, companion, __) =>
|
||||
_tab(companion.name, AppIcons.chat, 2),
|
||||
),
|
||||
_tab('我的', AppIcons.user, 3),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _tab(String label, String icon, int branch) {
|
||||
final active = widget.shell.currentIndex == branch;
|
||||
final color = active ? AppTheme.primary : context.jz.text3;
|
||||
|
||||
return Expanded(
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => widget.shell.goBranch(branch),
|
||||
child: SizedBox(
|
||||
height: double.infinity,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
AppIcons.icon(icon, size: 21, color: color),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: color,
|
||||
fontWeight: active ? FontWeight.w600 : null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _fab() {
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
final amount = await context.push<double>('/add');
|
||||
if (!mounted || amount == null) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('已记一笔 ¥${amount.toStringAsFixed(2)}')),
|
||||
);
|
||||
},
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 46,
|
||||
height: 46,
|
||||
margin: const EdgeInsets.only(top: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primary,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppTheme.primary.withValues(alpha: 0.24),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: AppIcons.icon(AppIcons.plus, size: 22, color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:miaoji_zhang/shared/api/api_client.dart';
|
||||
import 'package:miaoji_zhang/shared/api/business_api.dart';
|
||||
import 'package:miaoji_zhang/shared/theme/app_theme.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/category_icon.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/async_error_view.dart';
|
||||
import 'package:miaoji_zhang/shared/services/shanghai_time.dart';
|
||||
|
||||
/// 搜索页(P19)
|
||||
class SearchPage extends StatefulWidget {
|
||||
const SearchPage({super.key});
|
||||
|
||||
@override
|
||||
State<SearchPage> createState() => _SearchPageState();
|
||||
}
|
||||
|
||||
class _SearchPageState extends State<SearchPage> {
|
||||
final _input = TextEditingController();
|
||||
List<TxItem> _results = [];
|
||||
bool _aiOnly = false;
|
||||
bool _searched = false;
|
||||
bool _loading = false;
|
||||
String? _error;
|
||||
String? _timeFilter; // today | week | month
|
||||
double? _minAmount, _maxAmount;
|
||||
|
||||
Future<void> _search() async {
|
||||
final q = _input.text.trim();
|
||||
if (q.isEmpty &&
|
||||
!_aiOnly &&
|
||||
_timeFilter == null &&
|
||||
_minAmount == null &&
|
||||
_maxAmount == null)
|
||||
return;
|
||||
setState(() {
|
||||
_loading = true;
|
||||
_error = null;
|
||||
});
|
||||
try {
|
||||
final now = ShanghaiTime.now;
|
||||
DateTime? from;
|
||||
DateTime? to;
|
||||
if (_timeFilter == 'today') {
|
||||
from = DateTime(now.year, now.month, now.day);
|
||||
to = from.add(const Duration(days: 1));
|
||||
} else if (_timeFilter == 'week') {
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
from = today.subtract(Duration(days: today.weekday - 1));
|
||||
to = from.add(const Duration(days: 7));
|
||||
} else if (_timeFilter == 'month') {
|
||||
from = DateTime(now.year, now.month);
|
||||
to = DateTime(now.year, now.month + 1);
|
||||
}
|
||||
final list = await SearchApi.search(
|
||||
q: q,
|
||||
aiOnly: _aiOnly,
|
||||
minAmount: _minAmount,
|
||||
maxAmount: _maxAmount,
|
||||
from: from,
|
||||
to: to,
|
||||
);
|
||||
if (mounted)
|
||||
setState(() {
|
||||
_results = list;
|
||||
_searched = true;
|
||||
});
|
||||
} catch (error) {
|
||||
if (mounted) setState(() => _error = apiErrorMessage(error));
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final total = _results
|
||||
.where((t) => !t.isIncome)
|
||||
.fold<double>(0, (s, t) => s + t.amount);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: TextField(
|
||||
controller: _input,
|
||||
autofocus: true,
|
||||
textInputAction: TextInputAction.search,
|
||||
onSubmitted: (_) => _search(),
|
||||
decoration: InputDecoration(
|
||||
hintText: '搜备注 / 分类 / 你说过的话',
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||
),
|
||||
),
|
||||
actions: [TextButton(onPressed: _search, child: Text('搜索'))],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 6,
|
||||
children: [
|
||||
FilterChip(
|
||||
label: Text('仅 AI 记账', style: TextStyle(fontSize: 11)),
|
||||
selected: _aiOnly,
|
||||
selectedColor: context.jz.aiBackground,
|
||||
checkmarkColor: AppTheme.ai,
|
||||
onSelected: (v) {
|
||||
setState(() => _aiOnly = v);
|
||||
_search();
|
||||
},
|
||||
),
|
||||
...['today', 'week', 'month'].map(
|
||||
(t) => FilterChip(
|
||||
label: Text(
|
||||
{'today': '今天', 'week': '本周', 'month': '本月'}[t]!,
|
||||
style: TextStyle(fontSize: 11),
|
||||
),
|
||||
selected: _timeFilter == t,
|
||||
selectedColor: context.jz.primaryBackground,
|
||||
onSelected: (v) {
|
||||
setState(() => _timeFilter = v ? t : null);
|
||||
_search();
|
||||
},
|
||||
),
|
||||
),
|
||||
if (_searched && !_loading)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
child: Text(
|
||||
'${_results.length} 笔 · ¥${total.toStringAsFixed(2)}',
|
||||
style: TextStyle(fontSize: 11, color: context.jz.text3),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _loading
|
||||
? Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: AppTheme.primary,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
)
|
||||
: _error != null
|
||||
? AsyncErrorView(message: _error!, onRetry: _search)
|
||||
: !_searched
|
||||
? Center(
|
||||
child: Text(
|
||||
'输入关键词搜账单\n也能搜到你和 AI 说过的原话',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: context.jz.text3,
|
||||
height: 1.8,
|
||||
),
|
||||
),
|
||||
)
|
||||
: _results.isEmpty
|
||||
? Center(
|
||||
child: Text(
|
||||
'没有找到相关账单',
|
||||
style: TextStyle(fontSize: 12, color: context.jz.text3),
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
itemCount: _results.length,
|
||||
itemBuilder: (ctx, i) {
|
||||
final t = _results[i];
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 13,
|
||||
vertical: 10,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: context.jz.card,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: context.jz.line,
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
CategoryIconBox(
|
||||
iconKey: t.categoryIcon,
|
||||
colorKey: t.categoryColor,
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
t.note ?? t.categoryName,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 2),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'${t.occurredAt.month}月${t.occurredAt.day}日',
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
color: context.jz.text3,
|
||||
),
|
||||
),
|
||||
if (t.isAi) ...[
|
||||
SizedBox(width: 5),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 1.5,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: context.jz.aiBackground,
|
||||
borderRadius: BorderRadius.circular(
|
||||
6,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'✦ AI',
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
color: AppTheme.ai,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${t.isIncome ? '+' : '-'}${t.amount.toStringAsFixed(2)}',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: t.isIncome
|
||||
? AppTheme.primary
|
||||
: context.jz.text,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:miaoji_zhang/shared/api/api_client.dart';
|
||||
import 'package:miaoji_zhang/shared/api/business_api.dart';
|
||||
import 'package:miaoji_zhang/shared/services/current_ledger_store.dart';
|
||||
import 'package:miaoji_zhang/shared/theme/app_theme.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/app_controls.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/category_icon.dart';
|
||||
import 'package:miaoji_zhang/shared/services/shanghai_time.dart';
|
||||
|
||||
class TransactionEditPage extends StatefulWidget {
|
||||
final TxItem transaction;
|
||||
|
||||
const TransactionEditPage({super.key, required this.transaction});
|
||||
|
||||
@override
|
||||
State<TransactionEditPage> createState() => _TransactionEditPageState();
|
||||
}
|
||||
|
||||
class _TransactionEditPageState extends State<TransactionEditPage> {
|
||||
late final TextEditingController _amount;
|
||||
late final TextEditingController _note;
|
||||
late final TextEditingController _payment;
|
||||
late String _type;
|
||||
late int _ledgerId;
|
||||
late int _categoryId;
|
||||
late DateTime _occurredAt;
|
||||
List<CategoryItem> _categories = const [];
|
||||
bool _loading = true;
|
||||
bool _saving = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final transaction = widget.transaction;
|
||||
_amount = TextEditingController(
|
||||
text: transaction.amount.toStringAsFixed(2),
|
||||
);
|
||||
_note = TextEditingController(text: transaction.note ?? '');
|
||||
_payment = TextEditingController(text: transaction.paymentMethod ?? '');
|
||||
_type = transaction.type;
|
||||
_ledgerId = transaction.ledgerId;
|
||||
_categoryId = transaction.categoryId;
|
||||
_occurredAt = transaction.occurredAt;
|
||||
_loadCategories();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_amount.dispose();
|
||||
_note.dispose();
|
||||
_payment.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _loadCategories() async {
|
||||
setState(() => _loading = true);
|
||||
try {
|
||||
await CurrentLedgerStore.instance.ensureLoaded();
|
||||
final categories = await TxApi.categories(_type);
|
||||
if (!categories.any((category) => category.id == _categoryId) &&
|
||||
categories.isNotEmpty) {
|
||||
_categoryId = categories.first.id;
|
||||
}
|
||||
if (mounted) setState(() => _categories = categories);
|
||||
} catch (error) {
|
||||
if (mounted) _showError(error);
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _changeType(String type) async {
|
||||
if (type == _type) return;
|
||||
setState(() => _type = type);
|
||||
await _loadCategories();
|
||||
}
|
||||
|
||||
Future<void> _pickDateTime() async {
|
||||
final value = await showJzDateTimeSheet(
|
||||
context,
|
||||
initial: _occurredAt,
|
||||
firstDate: DateTime(2000),
|
||||
lastDate: ShanghaiTime.now.add(const Duration(days: 1)),
|
||||
title: '选择发生时间',
|
||||
);
|
||||
if (value != null && mounted) setState(() => _occurredAt = value);
|
||||
}
|
||||
|
||||
Future<void> _selectCategory() async {
|
||||
final value = await showJzOptionSheet<int>(
|
||||
context,
|
||||
title: '选择分类',
|
||||
options: _categories
|
||||
.map(
|
||||
(category) => JzOption(
|
||||
value: category.id,
|
||||
label: category.name,
|
||||
leading: CategoryIconBox(
|
||||
iconKey: category.iconKey,
|
||||
colorKey: category.colorKey,
|
||||
size: 32,
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
selected: _categoryId,
|
||||
);
|
||||
if (value != null && mounted) setState(() => _categoryId = value);
|
||||
}
|
||||
|
||||
Future<void> _selectLedger() async {
|
||||
final ledgers = CurrentLedgerStore.instance.ledgers;
|
||||
final value = await showJzOptionSheet<int>(
|
||||
context,
|
||||
title: '选择所属账本',
|
||||
options: ledgers
|
||||
.map(
|
||||
(ledger) => JzOption(
|
||||
value: ledger.id,
|
||||
label: ledger.name,
|
||||
subtitle: ledger.isDefault ? '当前默认账本' : null,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
selected: _ledgerId,
|
||||
);
|
||||
if (value != null && mounted) setState(() => _ledgerId = value);
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
final amount = double.tryParse(_amount.text.trim());
|
||||
if (amount == null || amount <= 0) {
|
||||
_showError(StateError('请输入正确金额'));
|
||||
return;
|
||||
}
|
||||
setState(() => _saving = true);
|
||||
try {
|
||||
final updated = await TxApi.update(
|
||||
widget.transaction.id,
|
||||
ledgerId: _ledgerId,
|
||||
categoryId: _categoryId,
|
||||
type: _type,
|
||||
amount: amount,
|
||||
note: _note.text.trim(),
|
||||
paymentMethod: _payment.text.trim(),
|
||||
occurredAt: _occurredAt,
|
||||
);
|
||||
if (mounted) Navigator.pop(context, updated);
|
||||
} catch (error) {
|
||||
if (mounted) _showError(error);
|
||||
} finally {
|
||||
if (mounted) setState(() => _saving = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _showError(Object error) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(apiErrorMessage(error))));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final ledgers = CurrentLedgerStore.instance.ledgers;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('编辑账单')),
|
||||
body: _loading
|
||||
? Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: AppTheme.primary,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
)
|
||||
: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
JzSegmentedControl<String>(
|
||||
value: _type,
|
||||
options: const [
|
||||
JzOption(value: 'expense', label: '支出'),
|
||||
JzOption(value: 'income', label: '收入'),
|
||||
],
|
||||
onChanged: _changeType,
|
||||
),
|
||||
SizedBox(height: 14),
|
||||
TextField(
|
||||
controller: _amount,
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
labelText: '金额',
|
||||
prefixText: '¥ ',
|
||||
),
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
_SelectField(
|
||||
label: '分类',
|
||||
value:
|
||||
_categories
|
||||
.where((category) => category.id == _categoryId)
|
||||
.map((category) => category.name)
|
||||
.firstOrNull ??
|
||||
'请选择',
|
||||
onTap: _selectCategory,
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
_SelectField(
|
||||
label: '所属账本',
|
||||
value:
|
||||
ledgers
|
||||
.where((ledger) => ledger.id == _ledgerId)
|
||||
.map((ledger) => ledger.name)
|
||||
.firstOrNull ??
|
||||
'请选择',
|
||||
onTap: _selectLedger,
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _note,
|
||||
maxLength: 50,
|
||||
decoration: InputDecoration(labelText: '备注'),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
TextField(
|
||||
controller: _payment,
|
||||
maxLength: 20,
|
||||
decoration: InputDecoration(labelText: '支付方式'),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text('发生时间'),
|
||||
subtitle: Text(_occurredAt.toString().substring(0, 16)),
|
||||
trailing: Icon(Icons.chevron_right),
|
||||
onTap: _pickDateTime,
|
||||
),
|
||||
if (widget.transaction.sourceText?.isNotEmpty == true) ...[
|
||||
SizedBox(height: 8),
|
||||
InputDecorator(
|
||||
decoration: InputDecoration(labelText: 'AI 原话(只读)'),
|
||||
child: Text(widget.transaction.sourceText!),
|
||||
),
|
||||
],
|
||||
SizedBox(height: 24),
|
||||
FilledButton(
|
||||
onPressed: _saving ? null : _save,
|
||||
child: Text(_saving ? '保存中...' : '保存修改'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SelectField extends StatelessWidget {
|
||||
final String label;
|
||||
final String value;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _SelectField({
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
child: InputDecorator(
|
||||
decoration: InputDecoration(labelText: label),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: TextStyle(fontSize: 13.5, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
Icon(Icons.keyboard_arrow_down_rounded, color: context.jz.text3),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:miaoji_zhang/features/home/pages/transaction_edit_page.dart';
|
||||
import 'package:miaoji_zhang/shared/services/transaction_events.dart';
|
||||
import 'package:miaoji_zhang/shared/api/business_api.dart';
|
||||
import 'package:miaoji_zhang/shared/theme/app_theme.dart';
|
||||
import 'package:miaoji_zhang/shared/services/shanghai_time.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/category_icon.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/app_icons.dart';
|
||||
|
||||
/// P11 账单详情:金额、分类、来源追溯(AI 原话)、时间、支付方式
|
||||
class TxDetailPage extends StatelessWidget {
|
||||
final TxItem tx;
|
||||
const TxDetailPage({super.key, required this.tx});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('账单详情'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: AppIcons.icon(
|
||||
AppIcons.edit,
|
||||
size: 18,
|
||||
color: context.jz.text2,
|
||||
),
|
||||
onPressed: () async {
|
||||
final updated = await Navigator.push<TxItem>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => TransactionEditPage(transaction: tx),
|
||||
),
|
||||
);
|
||||
if (updated != null && context.mounted) {
|
||||
TransactionEvents.notifyChanged();
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: AppIcons.icon(AppIcons.trash, size: 18, color: AppTheme.red),
|
||||
onPressed: () async {
|
||||
await TxApi.delete(tx.id);
|
||||
TransactionEvents.notifyChanged();
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
// 金额头部
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 28),
|
||||
margin: const EdgeInsets.only(bottom: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: context.jz.card,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
border: Border.all(color: context.jz.line, width: 0.5),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
'${tx.isIncome ? '+' : '-'}¥${tx.amount.toStringAsFixed(2)}',
|
||||
style: TextStyle(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: tx.isIncome ? AppTheme.primary : context.jz.text,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 6),
|
||||
Text(
|
||||
ShanghaiTime.formatCivil(tx.occurredAt),
|
||||
style: TextStyle(fontSize: 12, color: context.jz.text3),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// 分类
|
||||
_Row(
|
||||
k: '分类',
|
||||
child: Row(
|
||||
children: [
|
||||
CategoryIconBox(
|
||||
iconKey: tx.categoryIcon,
|
||||
colorKey: tx.categoryColor,
|
||||
size: 30,
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
Text(
|
||||
tx.categoryName,
|
||||
style: TextStyle(fontSize: 13.5, fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// 类型
|
||||
_Row(
|
||||
k: '类型',
|
||||
child: Text(
|
||||
tx.isIncome ? '收入' : '支出',
|
||||
style: TextStyle(fontSize: 13.5),
|
||||
),
|
||||
),
|
||||
// 备注
|
||||
if (tx.note != null && tx.note!.isNotEmpty)
|
||||
_Row(
|
||||
k: '备注',
|
||||
child: Text(tx.note!, style: TextStyle(fontSize: 13.5)),
|
||||
),
|
||||
// 支付方式
|
||||
if (tx.paymentMethod != null && tx.paymentMethod!.isNotEmpty)
|
||||
_Row(
|
||||
k: '支付方式',
|
||||
child: Text(tx.paymentMethod!, style: TextStyle(fontSize: 13.5)),
|
||||
),
|
||||
_Row(
|
||||
k: '记账方式',
|
||||
child: Row(
|
||||
children: [
|
||||
if (tx.isAi || tx.isRecognition) ...[
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 7,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: tx.isAi
|
||||
? context.jz.aiBackground
|
||||
: context.jz.primaryBackground,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
tx.isAi ? '✦ AI' : '智能识别',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: tx.isAi ? AppTheme.ai : AppTheme.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 7),
|
||||
],
|
||||
Text(tx.sourceLabel, style: TextStyle(fontSize: 13.5)),
|
||||
],
|
||||
),
|
||||
),
|
||||
if ((tx.isAi || tx.isRecognition) &&
|
||||
tx.sourceText != null &&
|
||||
tx.sourceText!.isNotEmpty)
|
||||
_Row(
|
||||
k: tx.isAi ? 'AI 原话' : '识别依据',
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: tx.isAi
|
||||
? context.jz.aiBackground
|
||||
: context.jz.primaryBackground,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'"${tx.sourceText}"',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: context.jz.text2,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// 来源标签
|
||||
_Row(
|
||||
k: '来源',
|
||||
child: Text(tx.sourceLabel, style: TextStyle(fontSize: 13.5)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Row extends StatelessWidget {
|
||||
final String k;
|
||||
final Widget child;
|
||||
const _Row({required this.k, required this.child});
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 13),
|
||||
margin: const EdgeInsets.only(bottom: 9),
|
||||
decoration: BoxDecoration(
|
||||
color: context.jz.card,
|
||||
borderRadius: BorderRadius.circular(13),
|
||||
border: Border.all(color: context.jz.line, width: 0.5),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 70,
|
||||
child: Text(
|
||||
k,
|
||||
style: TextStyle(fontSize: 12, color: context.jz.text3),
|
||||
),
|
||||
),
|
||||
Expanded(child: child),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user