Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 packages/talker/lib/src/talker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class Talker {
return;
}
if (data is TalkerLog) {
_handleLogData(data);
_handleLogData(data, logLevel: data.logLevel ?? LogLevel.info);
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/talker/lib/src/utils/error_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class TalkerErrorHandler {
if (exception is TalkerException) {
return exception;
}
if (exception is TalkerLog) {
return exception;
}

final errKey = TalkerKey.error;
final exceptionKey = TalkerKey.exception;
Expand Down
3 changes: 3 additions & 0 deletions packages/talker_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:talker_example/extended_example/extended_example.dart';
import 'package:talker_flutter/talker_flutter.dart';
// ignore: unused_import
import 'package:talker_example/talker_wrapper_example/talker_wrapper_example.dart';

/// You can see [ExtendedExample] to
/// check how logs working in realtime
Expand All @@ -21,6 +23,7 @@ void main() {
);
runZonedGuarded(
() => runApp(BaseExample(talker: talker)),
// () => runApp(CustomErrorMessagesExample(talker: talker)),
(Object error, StackTrace stack) {
talker.handle(error, stack, 'Uncaught app exception');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class _Home extends StatelessWidget {
onPressed: _handleError,
child: const Text('Handle error'),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: _handleLog,
child: const Text('Handle log message'),
),
],
),
),
Expand All @@ -71,6 +76,11 @@ class _Home extends StatelessWidget {
talker.handle(e, st);
}
}

void _handleLog() {
final talkerLog = TalkerLog('Test log message');
talker.handle(talkerLog);
}
}

class ExceptionSnackbar extends StatelessWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ class TalkerWrapper extends StatelessWidget {
title: options.errorTitle,
),
);
return;
}
if (data is TalkerLog && options.enableLogAlerts) {
showAlert(
context,
options.logAlertBuilder?.call(context, data) ??
SnackbarContent(
message: _mapErrorMessage(data.displayMessage),
title: data.title ?? options.logTitle,
),
);
}
},
child: child,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ class TalkerWrapperOptions {
const TalkerWrapperOptions({
this.exceptionTitle = 'Error occurred',
this.errorTitle = 'Error occurred',
this.logTitle = 'Log message',
this.exceptionAlertBuilder,
this.errorAlertBuilder,
this.logAlertBuilder,
this.enableErrorAlerts = false,
this.enableExceptionAlerts = true,
this.enableLogAlerts = true,
});

/// Used for custom snackbar title
Expand All @@ -17,15 +20,24 @@ class TalkerWrapperOptions {
/// Used for custom snackbar title
final String errorTitle;

/// Used for custom snackbar title
final String logTitle;

/// Field for customizing the displayed exception widget
final TalkerExceptionBuilder? exceptionAlertBuilder;

/// Field for customizing the displayed error widget
final TalkerErrorBuilder? errorAlertBuilder;

/// Field for customizing the displayed log widget
final TalkerDataBuilder? logAlertBuilder;

/// [TalkerWrapper] will show error message if field is [true]
final bool enableErrorAlerts;

/// [TalkerWrapper] will show exceptions message if field is [true]
final bool enableExceptionAlerts;

/// [TalkerWrapper] will show exceptions message if field is [true]
final bool enableLogAlerts;
}