Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error handling for CachedNetworkImage #18

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/core/infrastructure/services/location_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class LocationService {
timeLimit: const Duration(seconds: AppLocationSettings.getLocationTimeLimit),
);
} catch (e) {
Logger.root.shout(e.toString());
Logger.root.severe(e, StackTrace.current);
return null;
}
}
Expand Down
5 changes: 5 additions & 0 deletions lib/core/infrastructure/services/main_initializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ Future<ProviderContainer> _mainInitializer() async {
void _setupLogger() {
hierarchicalLoggingEnabled = true;
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((LogRecord r) {
if (r.loggerName.isEmpty) {
loggerOnDataCallback()?.call(r);
}
});
}

Future<void> _initFirebase() async {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import 'package:flutter/material.dart';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:logging/logging.dart';

import '../../../gen/my_assets.dart';
import '../../infrastructure/services/cache_service.dart';
import '../utils/riverpod_framework.dart';

void _reportImageError(WidgetRef ref, Object error) {
// You can also report to Crashlytics as non-fatal error.
Logger.root.severe(error, StackTrace.current);
}

class CachedNetworkImageCircular extends ConsumerWidget {
const CachedNetworkImageCircular({
required this.imageUrl,
Expand All @@ -27,8 +33,10 @@ class CachedNetworkImageCircular extends ConsumerWidget {
final cacheService = ref.watch(cacheServiceProvider);

return CachedNetworkImage(
key: UniqueKey(),
cacheManager: cacheService.customCacheManager,
errorListener: (error) {
_reportImageError(ref, error);
},
imageUrl: imageUrl != null && imageUrl!.contains('http') ? imageUrl! : spareImageUrl,
imageBuilder: (context, imageProvider) => CircleAvatar(
radius: radius,
Expand Down
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:logging/logging.dart';

import 'app.dart';
import 'core/infrastructure/local/shared_preferences_facade.dart';
import 'core/infrastructure/services/logger.dart';
import 'core/presentation/extensions/future_extensions.dart';
import 'core/presentation/providers/device_info_providers.dart';
import 'core/presentation/providers/provider_observers.dart';
Expand Down
Loading
Loading