mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-12 02:05:29 +00:00
Updated to embedding v2
Ref: https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects Fixes for sentry reporting Ref: https://github.com/flutter/flutter/issues/48972
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
@ -9,13 +10,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'dsn.dart';
|
||||
|
||||
import 'package:sentry/sentry.dart';
|
||||
|
||||
// Use the secret app key
|
||||
final SentryClient _sentry = SentryClient(
|
||||
SentryOptions(
|
||||
dsn: SENTRY_DSN_KEY,
|
||||
));
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
bool isInDebugMode() {
|
||||
bool inDebugMode = false;
|
||||
@ -26,33 +21,66 @@ bool isInDebugMode() {
|
||||
}
|
||||
|
||||
Future<void> _reportError(dynamic error, dynamic stackTrace) async {
|
||||
// Print the exception to the console.
|
||||
|
||||
print('Caught error: $error');
|
||||
|
||||
// Errors thrown in development mode are unlikely to be interesting. You can
|
||||
// check if you are running in dev mode using an assertion and omit sending
|
||||
// the report.
|
||||
if (isInDebugMode()) {
|
||||
// Print the full stacktrace in debug mode.
|
||||
print(stackTrace);
|
||||
print('In dev mode. Not sending report to Sentry.io.');
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
await _sentry.captureException(
|
||||
error,
|
||||
stackTrace: stackTrace
|
||||
);
|
||||
} catch (e) {
|
||||
print("Sending error report to sentry.io failed: ${e}");
|
||||
print("Original error: ${error}");
|
||||
}
|
||||
}
|
||||
|
||||
print('Reporting to Sentry.io...');
|
||||
|
||||
// Extract some platform information
|
||||
if (Platform.isIOS) {
|
||||
|
||||
} else if (Platform.isAndroid) {
|
||||
|
||||
}
|
||||
|
||||
Sentry.captureException(error, stackTrace: stackTrace).catchError((error) {
|
||||
print("Error uploading information to Sentry.io:");
|
||||
print(error);
|
||||
}).then((response) {
|
||||
print("Uploaded information to Sentry.io : ${response.toString()}");
|
||||
});
|
||||
}
|
||||
|
||||
void main() async {
|
||||
|
||||
|
||||
await Sentry.init((options) {
|
||||
options.dsn = SENTRY_DSN_KEY;
|
||||
},
|
||||
//appRunner: () => runApp(InvenTreeApp())
|
||||
);
|
||||
|
||||
await runZonedGuarded<Future<void>>(() async {
|
||||
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
runZoned<Future<void>>(() async {
|
||||
runApp(InvenTreeApp());
|
||||
}, onError: _reportError
|
||||
);
|
||||
// This captures errors reported by the Flutter framework.
|
||||
FlutterError.onError = (FlutterErrorDetails details) async {
|
||||
if (isInDebugMode()) {
|
||||
// In development mode simply print to console.
|
||||
FlutterError.dumpErrorToConsole(details);
|
||||
} else {
|
||||
// In production mode report to the application zone to report to
|
||||
// Sentry.
|
||||
Zone.current.handleUncaughtError(details.exception, details.stack);
|
||||
}
|
||||
};
|
||||
|
||||
runApp(InvenTreeApp());
|
||||
|
||||
}, (Object error, StackTrace stackTrace) {
|
||||
_reportError(error, stackTrace);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
class InvenTreeApp extends StatelessWidget {
|
||||
|
Reference in New Issue
Block a user