- 清理大量废弃的 barrel 导出文件,移除冗余的中间导出层 - 修复所有相对路径导入错误,统一调整为扁平化模块引用 - 更新多平台 pubspec 版本号与依赖库版本 - 补充后端功能问题管理后台与脚本工具 - 调整部分页面的快捷方式文案适配新功能 - 更新部分翻译覆盖率与API文档
77 lines
2.1 KiB
Dart
77 lines
2.1 KiB
Dart
/// ============================================================
|
||
/// 闲言APP — 点赞历史状态管理(服务端同步)
|
||
/// 创建时间: 2026-04-29
|
||
/// 更新时间: 2026-04-29
|
||
/// 作用: 点赞历史服务端同步状态管理,Feed API获取点赞列表
|
||
/// 上次更新: 初始创建
|
||
/// ============================================================
|
||
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||
|
||
import '../../../core/utils/logger.dart';
|
||
import '../feed_model.dart';
|
||
import '../services/feed_service.dart';
|
||
|
||
class LikesState {
|
||
const LikesState({
|
||
this.items = const [],
|
||
this.total = 0,
|
||
this.page = 1,
|
||
this.isLoading = false,
|
||
this.error,
|
||
});
|
||
|
||
final List<FeedItem> items;
|
||
final int total;
|
||
final int page;
|
||
final bool isLoading;
|
||
final String? error;
|
||
|
||
bool get hasMore => items.length < total;
|
||
|
||
LikesState copyWith({
|
||
List<FeedItem>? items,
|
||
int? total,
|
||
int? page,
|
||
bool? isLoading,
|
||
String? error,
|
||
bool clearError = false,
|
||
}) {
|
||
return LikesState(
|
||
items: items ?? this.items,
|
||
total: total ?? this.total,
|
||
page: page ?? this.page,
|
||
isLoading: isLoading ?? this.isLoading,
|
||
error: clearError ? null : (error ?? this.error),
|
||
);
|
||
}
|
||
}
|
||
|
||
class LikesNotifier extends Notifier<LikesState> {
|
||
@override
|
||
LikesState build() => const LikesState();
|
||
LikesNotifier();
|
||
|
||
Future<void> loadLikes({bool refresh = false}) async {
|
||
if (state.isLoading) return;
|
||
final page = refresh ? 1 : state.page;
|
||
state = state.copyWith(isLoading: true, clearError: true);
|
||
|
||
try {
|
||
final result = await FeedService.fetchLikes(page: page);
|
||
final newItems = refresh ? result.list : [...state.items, ...result.list];
|
||
state = state.copyWith(
|
||
items: newItems,
|
||
total: result.total,
|
||
page: page + 1,
|
||
isLoading: false,
|
||
);
|
||
} catch (e) {
|
||
Log.e('点赞历史加载失败', e);
|
||
state = state.copyWith(isLoading: false, error: '加载失败');
|
||
}
|
||
}
|
||
}
|
||
|
||
final likesProvider = NotifierProvider<LikesNotifier, LikesState>(LikesNotifier.new);
|