refactor(client): 只读判断统一走 WriteGuard 控件

将各屏内联的 ref.watch(isReadonlyProvider) 只读判断统一改为
WriteGuard(child:) 或 WriteGuard.isReadonly(ref),全项目只读逻辑
单一入口(仅 write_guard.dart 内部保留 provider 读取)。行为不变。

121 测试通过,analyze 无 error。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-17 00:56:31 +08:00
parent 196901b6d3
commit f15692bbd5
8 changed files with 48 additions and 45 deletions
@@ -11,7 +11,7 @@ import '../../widgets/page_scaffold.dart';
import '../../providers/connectivity_provider.dart';
import '../../core/utils/export_util.dart';
import '../../repositories/finance_repository.dart';
import '../../core/auth/auth_state.dart';
import '../../widgets/write_guard.dart';
class FinanceScreen extends ConsumerWidget {
const FinanceScreen({super.key});
@@ -161,7 +161,7 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
MobileCardField('状态', null, valueWidget: _StatusBadge(r.status)),
if (r.remark?.isNotEmpty == true) MobileCardField('备注', r.remark),
],
actions: (canClose && !ref.watch(isReadonlyProvider))
actions: (canClose && !WriteGuard.isReadonly(ref))
? [
TextButton(
onPressed: () => _closeRecord(r),
@@ -307,7 +307,7 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
case 'actions':
if ((r.type == 'payable' || r.type == 'receivable') &&
r.status == 'open' &&
!ref.watch(isReadonlyProvider)) {
!WriteGuard.isReadonly(ref)) {
return DataCell(TextButton(
onPressed: () => _closeRecord(r),
child: const Text('结清',
@@ -408,13 +408,13 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
},
toolbar: Row(
children: [
if (addLabel != null && !ref.watch(isReadonlyProvider))
if (addLabel != null && !WriteGuard.isReadonly(ref))
ElevatedButton.icon(
onPressed: _showAddDialog,
icon: const Icon(Icons.add, size: 16),
label: Text(addLabel),
),
if (addLabel != null && !ref.watch(isReadonlyProvider))
if (addLabel != null && !WriteGuard.isReadonly(ref))
const SizedBox(width: 8),
OutlinedButton.icon(
onPressed: () {