From 14161c5d429ee67b98f04d6d54a6cb6180a5e91d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 15 Feb 2021 20:30:39 +1100 Subject: [PATCH] Adds dialog before uploading error information --- lib/inventree/sentry.dart | 61 ++++++++++++++++++++++++++++----------- lib/main.dart | 7 ++--- lib/widget/dialogs.dart | 1 - pubspec.lock | 49 +++++++++++++++++++++++++++++++ pubspec.yaml | 3 +- 5 files changed, 98 insertions(+), 23 deletions(-) diff --git a/lib/inventree/sentry.dart b/lib/inventree/sentry.dart index ba3c1b2b..d3ed7ded 100644 --- a/lib/inventree/sentry.dart +++ b/lib/inventree/sentry.dart @@ -1,9 +1,12 @@ import 'dart:io'; import 'package:device_info/device_info.dart'; +import 'package:flutter/material.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:package_info/package_info.dart'; - import 'package:sentry_flutter/sentry_flutter.dart'; +import 'package:one_context/one_context.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import '../api.dart'; @@ -81,22 +84,7 @@ bool isInDebugMode() { return inDebugMode; } - -Future sentryReportError(dynamic error, dynamic stackTrace) async { - - 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(stackTrace); - print('In dev mode. Not sending report to Sentry.io.'); - return; - } - - print('Reporting to Sentry.io...'); - +Future _uploadErrorReport(dynamic error, dynamic stackTrace) async { final server_info = getServerInfo(); final app_info = await getAppInfo(); final device_info = await getDeviceInfo(); @@ -116,6 +104,45 @@ Future sentryReportError(dynamic error, dynamic stackTrace) async { } +Future sentryReportError(dynamic error, dynamic stackTrace) async { + + print('Intercepted error: $error'); + print(stackTrace); + + // 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('In dev mode. Not sending report to Sentry.io.'); + return; + } + + await OneContext().showDialog( + builder: (context) => AlertDialog( + title: ListTile( + title: Text(I18N.of(OneContext().context).error), + leading: FaIcon(FontAwesomeIcons.exclamationCircle), + subtitle: Text("An error occurred"), + ), + actions: [ + FlatButton( + child: Text("Upload Error Report"), + onPressed: () { + _uploadErrorReport(error, stackTrace); + OneContext().pop(); + }, + ) + ], + content: Text(error.toString()), + ) + ); + + return; + +} + + Future sentryReportMessage(String message) async { final server_info = getServerInfo(); diff --git a/lib/main.dart b/lib/main.dart index 6d12c06f..c27bef8c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,19 +5,16 @@ import 'package:InvenTree/inventree/sentry.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -import 'package:InvenTree/api.dart'; import 'package:InvenTree/widget/home.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:one_context/one_context.dart'; import 'dsn.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; - - - void main() async { @@ -58,6 +55,8 @@ class InvenTreeApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( + builder: OneContext().builder, + navigatorKey: OneContext().key, onGenerateTitle: (BuildContext context) => I18N.of(context).appTitle, theme: ThemeData( primarySwatch: Colors.lightBlue, diff --git a/lib/widget/dialogs.dart b/lib/widget/dialogs.dart index 3baa1c44..1e17dbcc 100644 --- a/lib/widget/dialogs.dart +++ b/lib/widget/dialogs.dart @@ -3,7 +3,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; Future confirmationDialog(BuildContext context, String title, String text, {String acceptText, String rejectText, Function onAccept, Function onReject}) async { diff --git a/pubspec.lock b/pubspec.lock index a48633c8..2e7d0cd4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -308,6 +308,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.3.0" + one_context: + dependency: "direct main" + description: + name: one_context + url: "https://pub.dartlang.org" + source: hosted + version: "0.5.0" package_info: dependency: "direct main" description: @@ -434,6 +441,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.0.4" + shared_preferences: + dependency: transitive + description: + name: shared_preferences + url: "https://pub.dartlang.org" + source: hosted + version: "0.5.12+4" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.2+4" + shared_preferences_macos: + dependency: transitive + description: + name: shared_preferences_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+11" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2+7" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.2+3" sky_engine: dependency: transitive description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index 7f7623ec..330582a0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,7 +7,7 @@ description: InvenTree stock management # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.1.0 +version: 0.1.0+2 environment: sdk: ">=2.1.0 <3.0.0" @@ -37,6 +37,7 @@ dependencies: camera: path_provider: ^1.6.27 # Local file storage sembast: ^2.4.9 # NoSQL data storage + one_context: ^0.5.0 # Dialogs without requiring context path: dev_dependencies: