Talker: Advanced Error Handling and Logging for Dart and Flutter Apps

Published on by Flutter News Hub

Talker: Advanced Error Handling and Logging for Dart and Flutter Apps

Talker is an exceptional error handling and logging library for Dart and Flutter applications, offering a comprehensive suite of features to enhance your app's stability and development process.

Key Features:

  • Error Handling: Precisely identifies errors and exceptions, providing stack traces and detailed error information.
  • Logging: Enables comprehensive logging with filtering, formatting, color customization, and level specification (info, warning, error, etc.).
  • Flutter Integration: Provides a wide range of Flutter-specific features, including logs sharing, HTTP call logging, UI error display, route monitoring, and customizable UI elements.
  • Third-Party Integrations: Seamlessly integrates with Crashlytics and other error tracking tools to streamline error reporting.

Customizable Configuration:

Talker's versatility stems from its highly customizable settings. You can tailor the library to your specific needs by modifying:

  • Filtering criteria
  • Log formatting
  • Color schemes

Example Usage:

Basic Logging:

import 'package:talker/talker.dart';

final talker = Talker();
talker.warning('The pizza is over 😥');
talker.debug('Thinking about order new one 🤔');

Error Handling:

try {
  throw Exception('The restaurant is closed ❌');
} catch (e, st) {
  talker.handle(e, st);
}

Flutter Integration - TalkerScreen:

import 'package:talker_flutter/talker_flutter.dart';

Navigator.of(context).push(
  MaterialPageRoute(
    builder: (context) => TalkerScreen(talker: talker),
  ),
);

TalkerRouteObserver:

import 'package:talker_flutter/talker_flutter.dart';

MaterialApp(
  navigatorObservers: [
    TalkerRouteObserver(talker),
  ],
);

TalkerWrapper for Custom UI Error Display:

import 'package:talker_flutter/talker_flutter.dart';

TalkerWrapper(
  talker: talker,
  options: const TalkerWrapperOptions(
    enableErrorAlerts: true,
  ),
  child: /// Application or the screen where you need to show messages
),

Integration with Crashlytics:

import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:talker/talker.dart';

class CrashlyticsTalkerObserver extends TalkerObserver {
  @override
  void onError(err) {
    FirebaseCrashlytics.instance.recordError(
      err.error,
      err.stackTrace,
      reason: err.message,
    );
  }

  @override
  void onException(err) {
    FirebaseCrashlytics.instance.recordError(
      err.exception,
      err.stackTrace,
      reason: err.message,
    );
  }
}

final crashlyticsTalkerObserver = CrashlyticsTalkerObserver();
final talker = Talker(observer: crashlyticsTalkerObserver);

In-Depth Features:

TalkerDioLogger:

  • Logs HTTP requests and responses with customizable colors and headers.
  • Filters logs based on request/response status codes and path patterns.

TalkerBlocLogger:

  • Logs BLoC events and state changes with customizable data truncation.
  • Selectively logs specific events and states using filters.

TalkerRiverpodLogger:

  • Logs Riverpod state changes and exceptions with full data or truncated.
  • Filters logs based on specific providers or state changes.

Conclusion:

Talker empowers developers with a comprehensive error handling and logging solution that streamlines app development. Its customizable settings, Flutter-specific features, and third-party integrations make it an indispensable tool for building robust and reliable applications.

Flutter News Hub