mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +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:
parent
3c560c395c
commit
fafaf8d036
@ -7,9 +7,11 @@
|
|||||||
additional functionality it is fine to subclass or reimplement
|
additional functionality it is fine to subclass or reimplement
|
||||||
FlutterApplication and put your custom class here. -->
|
FlutterApplication and put your custom class here. -->
|
||||||
<application
|
<application
|
||||||
android:name="io.flutter.app.FlutterApplication"
|
|
||||||
android:label="InvenTree"
|
android:label="InvenTree"
|
||||||
android:icon="@mipmap/ic_launcher">
|
android:icon="@mipmap/ic_launcher">
|
||||||
|
<meta-data
|
||||||
|
android:name="flutterEmbedding"
|
||||||
|
android:value="2" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop"
|
||||||
@ -17,13 +19,20 @@
|
|||||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize">
|
||||||
|
<!-- until Flutter renders its first frame. -->
|
||||||
|
<meta-data
|
||||||
|
android:name="io.flutter.embedding.android.SplashScreenDrawable"
|
||||||
|
android:resource="@drawable/launch_background" />
|
||||||
|
|
||||||
|
<!-- Theme to apply as soon as Flutter begins rendering frames -->
|
||||||
|
<meta-data
|
||||||
|
android:name="io.flutter.embedding.android.NormalTheme"
|
||||||
|
android:resource="@style/NormalTheme"
|
||||||
|
/>
|
||||||
<!-- This keeps the window background of the activity showing
|
<!-- This keeps the window background of the activity showing
|
||||||
until Flutter renders its first frame. It can be removed if
|
until Flutter renders its first frame. It can be removed if
|
||||||
there is no splash screen (such as the default splash screen
|
there is no splash screen (such as the default splash screen
|
||||||
defined in @style/LaunchTheme). -->
|
defined in @style/LaunchTheme). -->
|
||||||
<meta-data
|
|
||||||
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
|
|
||||||
android:value="true" />
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
|
@ -1,13 +1,6 @@
|
|||||||
package inventree.inventree_app;
|
package inventree.inventree_app;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import io.flutter.embedding.android.FlutterActivity;
|
||||||
import io.flutter.app.FlutterActivity;
|
|
||||||
import io.flutter.plugins.GeneratedPluginRegistrant;
|
|
||||||
|
|
||||||
public class MainActivity extends FlutterActivity {
|
public class MainActivity extends FlutterActivity {
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
GeneratedPluginRegistrant.registerWith(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,4 +5,8 @@
|
|||||||
Flutter draws its first frame -->
|
Flutter draws its first frame -->
|
||||||
<item name="android:windowBackground">@drawable/launch_background</item>
|
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||||
</style>
|
</style>
|
||||||
|
<!-- You can name this style whatever you'd like -->
|
||||||
|
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||||
|
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||||
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
@ -9,13 +10,7 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
import 'dsn.dart';
|
import 'dsn.dart';
|
||||||
|
|
||||||
import 'package:sentry/sentry.dart';
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||||
|
|
||||||
// Use the secret app key
|
|
||||||
final SentryClient _sentry = SentryClient(
|
|
||||||
SentryOptions(
|
|
||||||
dsn: SENTRY_DSN_KEY,
|
|
||||||
));
|
|
||||||
|
|
||||||
bool isInDebugMode() {
|
bool isInDebugMode() {
|
||||||
bool inDebugMode = false;
|
bool inDebugMode = false;
|
||||||
@ -26,33 +21,66 @@ bool isInDebugMode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _reportError(dynamic error, dynamic stackTrace) async {
|
Future<void> _reportError(dynamic error, dynamic stackTrace) async {
|
||||||
// Print the exception to the console.
|
|
||||||
print('Caught error: $error');
|
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()) {
|
if (isInDebugMode()) {
|
||||||
// Print the full stacktrace in debug mode.
|
|
||||||
print(stackTrace);
|
print(stackTrace);
|
||||||
|
print('In dev mode. Not sending report to Sentry.io.');
|
||||||
return;
|
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 {
|
void main() async {
|
||||||
|
|
||||||
|
|
||||||
|
await Sentry.init((options) {
|
||||||
|
options.dsn = SENTRY_DSN_KEY;
|
||||||
|
},
|
||||||
|
//appRunner: () => runApp(InvenTreeApp())
|
||||||
|
);
|
||||||
|
|
||||||
|
await runZonedGuarded<Future<void>>(() async {
|
||||||
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
runZoned<Future<void>>(() async {
|
// 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());
|
runApp(InvenTreeApp());
|
||||||
}, onError: _reportError
|
|
||||||
);
|
}, (Object error, StackTrace stackTrace) {
|
||||||
|
_reportError(error, stackTrace);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class InvenTreeApp extends StatelessWidget {
|
class InvenTreeApp extends StatelessWidget {
|
||||||
|
@ -421,12 +421,19 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.9"
|
version: "2.4.9"
|
||||||
sentry:
|
sentry:
|
||||||
dependency: "direct main"
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: sentry
|
name: sentry
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.4"
|
version: "4.0.4"
|
||||||
|
sentry_flutter:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: sentry_flutter
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "4.0.4"
|
||||||
shared_preferences:
|
shared_preferences:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -35,7 +35,7 @@ dependencies:
|
|||||||
device_info: ^1.0.0 # Information about the device
|
device_info: ^1.0.0 # Information about the device
|
||||||
font_awesome_flutter: ^8.8.1 # FontAwesome icon set
|
font_awesome_flutter: ^8.8.1 # FontAwesome icon set
|
||||||
flutter_speed_dial: ^1.2.5 # FAB menu elements
|
flutter_speed_dial: ^1.2.5 # FAB menu elements
|
||||||
sentry: ^4.0.4 # Error reporting
|
sentry_flutter: ^4.0.4 # Error reporting
|
||||||
flutter_typeahead: ^1.8.1 # Auto-complete input field
|
flutter_typeahead: ^1.8.1 # Auto-complete input field
|
||||||
image_picker: ^0.6.6 # Select or take photos
|
image_picker: ^0.6.6 # Select or take photos
|
||||||
url_launcher: ^5.7.10 # Open link in system browser
|
url_launcher: ^5.7.10 # Open link in system browser
|
||||||
|
Loading…
x
Reference in New Issue
Block a user