Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds different entry points to dev and prod #260

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 8 additions & 51 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// This program is free software: you can redistribute it and/or modify
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation, either version 3 of the License, or
/// (at your option) any later version.
Expand All @@ -11,56 +11,13 @@
/// You should have received a copy of the GNU General Public License
/// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'dart:async';
import 'dart:io';
import 'package:covid19mobile/services/messaging_service.dart';
import 'package:covid19mobile/ui/app.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';

AppConfig appConfig;
import 'package:covid19mobile/main_common.dart';

/// Main Entry point for DEV
///
/// To run the dev configuration, please use the following command:
///
/// `flutter run`
void main() async {
final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized();

/// Override automaticSystemUiAdjustment auto UI color overlay adjustment
/// on Android
if (Platform.isAndroid) {
binding.renderView.automaticSystemUiAdjustment = false;
}

var enableInDevMode = true;

/// Set `enableInDevMode` to true to see reports while in debug mode
/// This is only to be used for confirming that reports are being
/// submitted as expected. It is not intended to be used for everyday
/// development.
Crashlytics.instance.enableInDevMode = enableInDevMode;

/// Pass all uncaught errors from the framework to Crashlytics.
FlutterError.onError = Crashlytics.instance.recordFlutterError;

appConfig = AppConfig.dev;

/// Init Firebase messaging service
await MessagingService.init();

runZoned<Future<void>>(() async {
/// Run main app
runApp(CovidApp());
}, onError: (e, s) {
/// Register and sends error
Crashlytics.instance.recordError(e, s);

/// for debug:
if (enableInDevMode) {
logger.e('[Error]: ${e.toString()}');
logger.e('[Stacktrace]: ${s.toString()}');
}
});
}

enum AppConfig {
dev,
prod,
mainCommon(AppConfig.prod);
}
70 changes: 70 additions & 0 deletions lib/main_common.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation, either version 3 of the License, or
/// (at your option) any later version.
///
/// This program is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'dart:async';
import 'dart:io';
import 'package:covid19mobile/services/messaging_service.dart';
import 'package:covid19mobile/ui/app.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';

AppConfig appConfig;

/// Common entrypoint for the COVID-19 App
///
/// This will initialize the app given an [AppConfig] configuration
void mainCommon(AppConfig appConfig) async {
final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized();

/// Override automaticSystemUiAdjustment auto UI color overlay adjustment
/// on Android
if (Platform.isAndroid) {
binding.renderView.automaticSystemUiAdjustment = false;
}

var enableInDevMode = true;

/// Set `enableInDevMode` to true to see reports while in debug mode
/// This is only to be used for confirming that reports are being
/// submitted as expected. It is not intended to be used for everyday
/// development.
Crashlytics.instance.enableInDevMode = enableInDevMode;

/// Pass all uncaught errors from the framework to Crashlytics.
FlutterError.onError = Crashlytics.instance.recordFlutterError;

/// Sets appConfig globally
appConfig = AppConfig.dev;

/// Init Firebase messaging service
await MessagingService.init();

runZoned<Future<void>>(() async {
/// Run main app
runApp(CovidApp());
}, onError: (e, s) {
/// Register and sends error
Crashlytics.instance.recordError(e, s);

/// for debug:
if (enableInDevMode) {
logger.e('[Error]: ${e.toString()}');
logger.e('[Stacktrace]: ${s.toString()}');
}
});
}

enum AppConfig {
dev,
prod,
}
23 changes: 23 additions & 0 deletions lib/main_dev.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation, either version 3 of the License, or
/// (at your option) any later version.
///
/// This program is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'package:covid19mobile/main_common.dart';

/// Main Entry point for DEV
///
/// To run the dev configuration, please use the following command:
///
/// `flutter run -t lib/main_dev.dart`
void main() async {
mainCommon(AppConfig.dev);
}
2 changes: 1 addition & 1 deletion lib/model/post_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// You should have received a copy of the GNU General Public License
/// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'package:covid19mobile/main.dart';
import 'package:covid19mobile/main_common.dart';

/// Post types
enum PostTypes {
Expand Down
2 changes: 1 addition & 1 deletion lib/services/covid_status/status_api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// You should have received a copy of the GNU General Public License
/// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'package:covid19mobile/main.dart';
import 'package:covid19mobile/main_common.dart';
import 'package:covid19mobile/model/api_response_model.dart';
import 'package:covid19mobile/services/covid_status/status_api.dart';
import 'package:covid19mobile/services/request_type.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/services/estamoson/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import 'dart:async';

import 'package:covid19mobile/main.dart';
import 'package:covid19mobile/main_common.dart';
import 'package:covid19mobile/model/api_response_model.dart';
import 'package:covid19mobile/model/post_type.dart';
import 'package:covid19mobile/services/estamoson/api.dart';
Expand Down