Skip to content

Instantly share code, notes, and snippets.

@mono0926
Created December 22, 2022 07:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mono0926/5ad9e304515cf1c4733b75ea08466230 to your computer and use it in GitHub Desktop.
Save mono0926/5ad9e304515cf1c4733b75ea08466230 to your computer and use it in GitHub Desktop.
class PackageMetrics extends StateNotifier<AsyncValue<PackageMetricsScore>> {
PackageMetrics(this._ref, {required this.packageName})
: super(const AsyncLoading()) {
_ref
.watch(pubRepositoryProvider)
.getPackageMetrics(packageName: packageName)
.then((value) => state = AsyncData(value));
}
final AutoDisposeRef _ref;
final String packageName;
Future<void> like() async {
await _ref.read(pubRepositoryProvider).like(packageName: packageName);
_ref.invalidateSelf();
_ref.invalidate(likedPackagesProvider);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment