Skip to content

Commit

Permalink
Improve logger snackbar and open gleap (#869)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by OSS
Entelligence.AI -->
### Summary by Entelligence.AI

- New Feature: Introduced `LoggerSnackbar` widget for enhanced error and
exception handling. This feature provides a user-friendly way to display
errors and exceptions.
- Refactor: Updated the `_MyAppState` class to use the new
`LoggerSnackbar` widget in `exceptionAlertBuilder` and
`errorAlertBuilder`, improving the visibility and clarity of error
messages.
- New Feature: Added an action button within the `LoggerSnackbar` widget
that allows users to share errors for further investigation, enhancing
the app's debugging capabilities.
<!-- end of auto-generated comment: release notes by OSS Entelligence.AI
-->
  • Loading branch information
beastoin authored Sep 17, 2024
2 parents 327aef7 + 3497e7e commit d23b426
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
24 changes: 4 additions & 20 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,27 +246,11 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
options: TalkerWrapperOptions(
enableErrorAlerts: true,
enableExceptionAlerts: true,
errorAlertBuilder: (context, data) {
return LoggerSnackbar(error: data);
},
exceptionAlertBuilder: (context, data) {
return Container(
width: double.infinity,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10),
),
child: ListTile(
contentPadding: const EdgeInsets.all(0),
leading: const Icon(Icons.error_outline, color: Colors.white),
title: Text(
data.message ?? 'Something went wrong! Please try again later.',
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
trailing: IconButton(
icon: const Icon(Icons.share, color: Colors.white),
onPressed: () {},
),
),
);
return LoggerSnackbar(exception: data);
},
),
child: const DeciderWidget(),
Expand Down
36 changes: 36 additions & 0 deletions app/lib/utils/logger.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:flutter/material.dart';
import 'package:gleap_sdk/gleap_sdk.dart';
import 'package:talker_flutter/talker_flutter.dart';

class Logger {
Expand Down Expand Up @@ -33,3 +35,37 @@ class Logger {
instance.talker.handle(exception, stackTrace, message ?? 'An error occurred. Please try again later.');
}
}

class LoggerSnackbar extends StatelessWidget {
final TalkerError? error;
final TalkerException? exception;
const LoggerSnackbar({super.key, this.error, this.exception}) : assert(error != null || exception != null);

@override
Widget build(BuildContext context) {
final data = error ?? exception!;
return Container(
width: double.infinity,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10),
),
child: ListTile(
contentPadding: const EdgeInsets.all(0),
leading: const Icon(Icons.error_outline, color: Colors.white),
title: Text(
data.message ?? 'Something went wrong! Please try again later.',
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
trailing: IconButton(
icon: const Icon(Icons.share, color: Colors.white),
onPressed: () async {
// TODO: Have a custom form which can be prefilled with the error stack trace instead of opening the Gleap Homepage
await Gleap.open();
},
),
),
);
}
}

0 comments on commit d23b426

Please sign in to comment.