mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-25 17:00:39 +00:00
run app with runZonedGuarded
This commit is contained in:
parent
147fedc36f
commit
dc9aa7bc1d
6 changed files with 51 additions and 64 deletions
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
|
@ -41,7 +41,7 @@
|
|||
"--dart-define",
|
||||
"cameraPreviewAspectRatio=240/320",
|
||||
],
|
||||
"program": "${workspaceFolder}/lib/main_release.dart",
|
||||
"program": "${workspaceFolder}/lib/main_prod.dart",
|
||||
},
|
||||
{
|
||||
"name": "prod-profile (android)",
|
||||
|
@ -54,7 +54,7 @@
|
|||
"--dart-define",
|
||||
"cameraPreviewAspectRatio=240/320",
|
||||
],
|
||||
"program": "${workspaceFolder}/lib/main_release.dart",
|
||||
"program": "${workspaceFolder}/lib/main_prod.dart",
|
||||
},
|
||||
{
|
||||
"name": "dev-debug (ios)",
|
||||
|
|
|
@ -9,11 +9,19 @@ class LightmeterAnalytics {
|
|||
|
||||
const LightmeterAnalytics({required ILightmeterAnalyticsApi api}) : _api = api;
|
||||
|
||||
void init() {
|
||||
FlutterError.onError = (details) => logCrash(details.exception, details.stack);
|
||||
PlatformDispatcher.instance.onError = (error, stack) {
|
||||
logCrash(error, stack);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> logEvent(
|
||||
String eventName, {
|
||||
Map<String, dynamic>? parameters,
|
||||
}) async {
|
||||
if (kDebugMode) {
|
||||
if (!kReleaseMode) {
|
||||
log('<LightmeterAnalytics> logEvent: $eventName / $parameters');
|
||||
return;
|
||||
}
|
||||
|
@ -26,17 +34,17 @@ class LightmeterAnalytics {
|
|||
|
||||
Future<void> logCrash(
|
||||
dynamic exception,
|
||||
StackTrace? stack, {
|
||||
StackTrace? stackTrace, {
|
||||
dynamic reason,
|
||||
Iterable<Object> information = const [],
|
||||
}) async {
|
||||
if (kDebugMode) {
|
||||
if (!kReleaseMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
return _api.logCrash(
|
||||
exception,
|
||||
stack,
|
||||
stackTrace,
|
||||
reason: reason,
|
||||
information: information,
|
||||
);
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:lightmeter/firebase_options.dart';
|
||||
|
||||
Future<void> initializeFirebase({required bool handleErrors}) async {
|
||||
try {
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
if (handleErrors) {
|
||||
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
|
||||
PlatformDispatcher.instance.onError = (error, stack) {
|
||||
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
}
|
||||
}
|
|
@ -1,19 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/application.dart';
|
||||
import 'package:lightmeter/application_wrapper.dart';
|
||||
import 'package:lightmeter/environment.dart';
|
||||
import 'package:lightmeter/firebase.dart';
|
||||
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||
import 'package:lightmeter/runner.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await initializeFirebase(handleErrors: true);
|
||||
runApp(
|
||||
const IAPProductsProvider(
|
||||
child: ApplicationWrapper(
|
||||
Environment.prod(),
|
||||
child: Application(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Future<void> main() => runLightmeterApp(const Environment.prod());
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/application.dart';
|
||||
import 'package:lightmeter/application_wrapper.dart';
|
||||
import 'package:lightmeter/environment.dart';
|
||||
import 'package:lightmeter/firebase.dart';
|
||||
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await initializeFirebase(handleErrors: false);
|
||||
runApp(
|
||||
const IAPProductsProvider(
|
||||
child: ApplicationWrapper(
|
||||
Environment.prod(),
|
||||
child: Application(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
35
lib/runner.dart
Normal file
35
lib/runner.dart
Normal file
|
@ -0,0 +1,35 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:lightmeter/application.dart';
|
||||
import 'package:lightmeter/application_wrapper.dart';
|
||||
import 'package:lightmeter/data/analytics/analytics.dart';
|
||||
import 'package:lightmeter/data/analytics/api/analytics_firebase.dart';
|
||||
import 'package:lightmeter/environment.dart';
|
||||
import 'package:lightmeter/firebase_options.dart';
|
||||
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||
|
||||
const _errorsLogger = LightmeterAnalytics(api: LightmeterAnalyticsFirebase());
|
||||
|
||||
Future<void> runLightmeterApp(Environment env) async {
|
||||
runZonedGuarded(
|
||||
() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
if (env.buildType == BuildType.prod) {
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
}
|
||||
_errorsLogger.init();
|
||||
final application = ApplicationWrapper(env, child: const Application());
|
||||
runApp(
|
||||
env.buildType == BuildType.dev
|
||||
? IAPProducts(
|
||||
products: [IAPProduct(storeId: IAPProductType.paidFeatures.storeId)],
|
||||
child: application,
|
||||
)
|
||||
: IAPProductsProvider(child: application),
|
||||
);
|
||||
},
|
||||
_errorsLogger.logCrash,
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue