/// 仓储接口:应用层只依赖这个抽象,不依赖 drift / http。 /// /// 对照 Go:接口 + 实现注入;对照 C:函数指针表。Riverpod 的 override 就是注入手段。 library; import 'bookmark.dart'; abstract interface class BookmarkRepository { /// 响应式列表:数据一变就推新值(drift 的 watch)。 Stream> watchAll(); Future add(BookmarkDraft draft); Future setFavorite(int id, {required bool favorite}); Future delete(int id); /// 从远程导入若干条,返回实际写入的数量。 Future importFromRemote({int limit = 10}); } /// 远程数据源接口:实现可以是 http、可以是为测试写的假实现。 abstract interface class BookmarkRemoteApi { Future> fetchDrafts({int limit = 10}); } /// 同步失败(网络/解析),带用户可读文案。 class SyncException implements Exception { const SyncException(this.message, {this.cause}); final String message; final Object? cause; @override String toString() => 'SyncException: $message'; }