my_riverpod_observer.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import 'package:flutter_riverpod/flutter_riverpod.dart';
  2. import 'package:shared/utils/log_utils.dart';
  3. class MyRiverpodObserver extends ProviderObserver {
  4. @override
  5. void didAddProvider(
  6. ProviderBase<Object?> provider,
  7. Object? value,
  8. ProviderContainer container,
  9. ) {
  10. Log.d('Riverpod Provider Did Add -> $provider was initialized with $value');
  11. }
  12. @override
  13. void didDisposeProvider(
  14. ProviderBase<Object?> provider,
  15. ProviderContainer container,
  16. ) {
  17. Log.d('Riverpod Provider Did Dispose -> $provider was disposed');
  18. }
  19. @override
  20. void didUpdateProvider(
  21. ProviderBase<Object?> provider,
  22. Object? previousValue,
  23. Object? newValue,
  24. ProviderContainer container,
  25. ) {
  26. Log.d(
  27. 'Riverpod Provider Did Update -> $provider updated from $previousValue to $newValue',
  28. );
  29. }
  30. @override
  31. void providerDidFail(
  32. ProviderBase<Object?> provider,
  33. Object error,
  34. StackTrace stackTrace,
  35. ProviderContainer container,
  36. ) {
  37. Log.d('Riverpod Provider Did Fail -> $provider threw $error at $stackTrace');
  38. }
  39. }