forked from eatvio/eatvio_app
fixed sentry crashes handling
This commit is contained in:
@@ -18,21 +18,22 @@ class AppInitializer {
|
||||
static Future<void> initialize({required AppBuildType buildType}) async {
|
||||
await _initializeEnvironment();
|
||||
await _initializeDependencyInjection(buildType: buildType);
|
||||
await _initializeSentry();
|
||||
_preserveSplash();
|
||||
await _initializeFirebase();
|
||||
await _initializeDebugMode();
|
||||
await _initializeAnalytics();
|
||||
}
|
||||
|
||||
/// Инициализация Sentry
|
||||
static Future<void> _initializeSentry() async {
|
||||
static void _preserveSplash() {
|
||||
final widgetsBinding = SentryWidgetsFlutterBinding.ensureInitialized();
|
||||
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
|
||||
}
|
||||
|
||||
/// Загрузка переменных окружения
|
||||
static Future<void> _initializeEnvironment() async {
|
||||
await dotenv.load(fileName: ".env");
|
||||
if (!dotenv.isInitialized) {
|
||||
await dotenv.load(fileName: '.env');
|
||||
}
|
||||
}
|
||||
|
||||
/// Инициализация Firebase
|
||||
@@ -64,20 +65,25 @@ class AppInitializer {
|
||||
|
||||
/// Инициализация аналитики
|
||||
static Future<void> _initializeAnalytics() async {
|
||||
AppMetrica.activate(AppMetricaConfig(EnvConfig.appMetricaApiKey));
|
||||
AppMetrica.activate(AppMetricaConfig(EnvConfig.appMetricaApiKey, flutterCrashReporting: false));
|
||||
AppMetrica.reportEvent('Application started');
|
||||
}
|
||||
|
||||
/// Запуск приложения с Sentry
|
||||
static Future<void> runAppWithSentry(VoidCallback appRunner) async {
|
||||
static Future<void> runAppWithSentry(
|
||||
FutureOr<void> Function() appRunner,
|
||||
) async {
|
||||
SentryWidgetsFlutterBinding.ensureInitialized();
|
||||
await _initializeEnvironment();
|
||||
const sendInDebug = bool.fromEnvironment('SENTRY_IN_DEBUG');
|
||||
await SentryFlutter.init((options) {
|
||||
options.dsn = EnvConfig.sentryDsn;
|
||||
options.tracesSampleRate = 1.0;
|
||||
options.debug = false;
|
||||
if (kDebugMode && sendInDebug) options.environment = 'debug';
|
||||
options.beforeSend = (event, hint) {
|
||||
if (kDebugMode) return null;
|
||||
if (!ErrorReportPolicy.allowSentryEvent(event, hint)) return null;
|
||||
return event;
|
||||
if (kDebugMode && !sendInDebug) return null;
|
||||
return ErrorReportPolicy.prepareSentryEvent(event, hint);
|
||||
};
|
||||
}, appRunner: appRunner);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user