From 4201d36abb202787691121ea48b3dbb38cde2e09 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Sun, 3 Sep 2023 13:06:30 +0200 Subject: [PATCH] Refined launch options --- .gitignore | 2 +- .vscode/launch.json | 66 ++++++++++++++++++++++++++++++------------- README.md | 11 ++++++-- lib/firebase.dart | 22 ++++++++++----- lib/main_prod.dart | 8 +----- lib/main_release.dart | 10 +++++++ 6 files changed, 82 insertions(+), 37 deletions(-) create mode 100644 lib/main_release.dart diff --git a/.gitignore b/.gitignore index ee0aebd..3fd9832 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,6 @@ keystore.properties android/app/google-services.json ios/firebase_app_id_file.json ios/Runner/GoogleService-Info.plist -lib/firebase_options.dart +/lib/firebase_options.dart coverage/ \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 6cbc2bc..40dbfac 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,9 +5,10 @@ "version": "0.2.0", "configurations": [ { - "name": "dev (android)", + "name": "dev-debug (android)", "request": "launch", "type": "dart", + "flutterMode": "debug", "args": [ "--flavor", "dev", @@ -17,9 +18,49 @@ "program": "${workspaceFolder}/lib/main_dev.dart", }, { - "name": "dev (ios)", + "name": "dev-profile (android)", "request": "launch", "type": "dart", + "flutterMode": "profile", + "args": [ + "--flavor", + "dev", + "--dart-define", + "cameraPreviewAspectRatio=240/320", + ], + "program": "${workspaceFolder}/lib/main_dev.dart", + }, + { + "name": "prod-debug (android)", + "request": "launch", + "type": "dart", + "flutterMode": "debug", + "args": [ + "--flavor", + "prod", + "--dart-define", + "cameraPreviewAspectRatio=240/320", + ], + "program": "${workspaceFolder}/lib/main_release.dart", + }, + { + "name": "prod-profile (android)", + "request": "launch", + "type": "dart", + "flutterMode": "profile", + "args": [ + "--flavor", + "prod", + "--dart-define", + "cameraPreviewAspectRatio=240/320", + ], + "program": "${workspaceFolder}/lib/main_release.dart", + }, + { + "name": "dev-debug (ios)", + "request": "launch", + "type": "dart", + "flutterMode": "debug", "args": [ "--flavor", "dev", @@ -29,30 +70,17 @@ "program": "${workspaceFolder}/lib/main_dev.dart", }, { - "name": "prod (android)", + "name": "dev-profile (ios)", "request": "launch", - //"flutterMode": "release", + "flutterMode": "profile", "type": "dart", "args": [ "--flavor", - "prod", - "--dart-define", - "cameraPreviewAspectRatio=240/320", - ], - "program": "${workspaceFolder}/lib/main_prod.dart", - }, - { - "name": "prod (ios)", - "request": "launch", - //"flutterMode": "release", - "type": "dart", - "args": [ - "--flavor", - "prod", + "dev", "--dart-define", "cameraPreviewAspectRatio=3/4", ], - "program": "${workspaceFolder}/lib/main_prod.dart", + "program": "${workspaceFolder}/lib/main_dev.dart", }, ], } \ No newline at end of file diff --git a/README.md b/README.md index c4af94a..08e5780 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,18 @@ flutter pub get flutter pub run intl_utils:generate ``` -### 4. Build (Android) +### 4. Build + +#### Android You can build an apk by running the following command from the root of the repository: ```console -flutter build apk --release --flavor $FLAVOR --dart-define cameraPreviewAspectRatio=240/320 -t lib/main_$FLAVOR.dart +flutter build apk --release --flavor dev --dart-define cameraPreviewAspectRatio=240/320 -t lib/main_dev.dart ``` -Just replace `$FLAVOR` with `dev` or `prod`. + +### iOS + +TBD # Contribution diff --git a/lib/firebase.dart b/lib/firebase.dart index f75ae90..0a0e6b0 100644 --- a/lib/firebase.dart +++ b/lib/firebase.dart @@ -1,14 +1,22 @@ +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 initializeFirebase() async { - await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); - FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError; - PlatformDispatcher.instance.onError = (error, stack) { - FirebaseCrashlytics.instance.recordError(error, stack, fatal: true); - return true; - }; +Future 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()); + } } diff --git a/lib/main_prod.dart b/lib/main_prod.dart index fc1700a..2ccc397 100644 --- a/lib/main_prod.dart +++ b/lib/main_prod.dart @@ -1,5 +1,3 @@ -import 'dart:developer'; - import 'package:flutter/material.dart'; import 'package:lightmeter/application.dart'; import 'package:lightmeter/environment.dart'; @@ -7,10 +5,6 @@ import 'package:lightmeter/firebase.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); - try { - await initializeFirebase(); - } catch (e) { - log(e.toString()); - } + await initializeFirebase(handleErrors: true); runApp(const Application(Environment.prod())); } diff --git a/lib/main_release.dart b/lib/main_release.dart new file mode 100644 index 0000000..b87dff8 --- /dev/null +++ b/lib/main_release.dart @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; +import 'package:lightmeter/application.dart'; +import 'package:lightmeter/environment.dart'; +import 'package:lightmeter/firebase.dart'; + +Future main() async { + WidgetsFlutterBinding.ensureInitialized(); + await initializeFirebase(handleErrors: false); + runApp(const Application(Environment.prod())); +}