Skip to content

Commit

Permalink
Update firebase and run flutterfire configure
Browse files Browse the repository at this point in the history
  • Loading branch information
Abestanis committed Jun 27, 2024
1 parent 3166475 commit 72f46e7
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 89 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ pubspec.lock linguist-generated=true
.metadata linguist-generated=true
# Generated files by the theme_tailor library
*.tailor.dart linguist-generated=true
# Generated files by the firebase library
lib/firebase_options.dart linguist-generated=true
23 changes: 11 additions & 12 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
plugins {
id "com.android.application"
// START: FlutterFire Configuration
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
// END: FlutterFire Configuration
id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -21,12 +32,6 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services' // Google Services plugin
apply plugin: 'com.google.firebase.crashlytics'

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
Expand Down Expand Up @@ -80,9 +85,3 @@ android {
flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-crashlytics:17.4.1'
implementation 'com.google.firebase:firebase-analytics:18.0.3'
}
15 changes: 0 additions & 15 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10' // Google Services plugin
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2'
}
}

allprojects {
repositories {
google()
Expand Down
34 changes: 26 additions & 8 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
include ':app'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
// START: FlutterFire Configuration
id "com.google.gms.google-services" version "4.3.15" apply false
id "com.google.firebase.crashlytics" version "2.8.1" apply false
// END: FlutterFire Configuration
id "org.jetbrains.kotlin.android" version "1.9.10" apply false
}

include ":app"
1 change: 1 addition & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"flutter":{"platforms":{"android":{"default":{"projectId":"sweyer-def42","appId":"1:574502524315:android:b7be71579f4098be31fd3e","fileOutput":"android/app/google-services.json"}},"dart":{"lib/firebase_options.dart":{"projectId":"sweyer-def42","configurations":{"android":"1:574502524315:android:b7be71579f4098be31fd3e"}}}}}}
64 changes: 64 additions & 0 deletions lib/firebase_options.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 39 additions & 34 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:sweyer/constants.dart' as constants;
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'firebase_options.dart';

/// Builds up the error report message from the exception and stacktrace.
String buildErrorReport(dynamic ex, dynamic stack) {
Expand All @@ -19,12 +20,14 @@ $ex
$stack''';
}

Future<void> reportError(dynamic ex, StackTrace stack) async {
Future<void> reportError(dynamic error, StackTrace stack) async {
if (Prefs.isInitialized && Prefs.devMode.get()) {
ShowFunctions.instance.showError(errorDetails: buildErrorReport(ex, stack));
ShowFunctions.instance.showError(
errorDetails: buildErrorReport(error, stack),
);
}
if (Firebase.apps.isNotEmpty) {
await FirebaseCrashlytics.instance.recordError(ex, stack);
await FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
}
}

Expand Down Expand Up @@ -66,38 +69,40 @@ class _WidgetsBindingObserver extends WidgetsBindingObserver {
}

Future<void> main() async {
runZonedGuarded(() async {
// Disabling automatic system UI adjustment, which causes system nav bar
// color to be reverted to black when the bottom player route is being expanded.
//
// Related to https://github.com/flutter/flutter/issues/40590
final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized();
binding.renderView.automaticSystemUiAdjustment = false;
await NFPrefs.initialize();

await Firebase.initializeApp();
if (kDebugMode) {
FirebaseFunctions.instance.useFunctionsEmulator('http://localhost/', 5001);

// Force disable Crashlytics collection while doing every day development.
// Temporarily toggle this to true if you want to test crash reporting in your app.
await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false);
}
// Disabling automatic system UI adjustment, which causes system nav bar
// color to be reverted to black when the bottom player route is being expanded.
//
// Related to https://github.com/flutter/flutter/issues/40590
final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized();
binding.renderView.automaticSystemUiAdjustment = false;
await NFPrefs.initialize();

await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
if (kDebugMode) {
FirebaseFunctions.instance.useFunctionsEmulator('http://localhost/', 5001);

// Force disable Crashlytics collection while doing every day development.
// Temporarily toggle this to true if you want to test crash reporting in your app.
await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false);
}

Isolate.current.addErrorListener(RawReceivePort((pair) async {
final List<dynamic> errorAndStacktrace = pair;
await reportError(errorAndStacktrace.first, errorAndStacktrace.last);
}).sendPort);
FlutterError.onError = reportFlutterError;
WidgetsBinding.instance.addObserver(_WidgetsBindingObserver());

await DeviceInfoControl.instance.init();
ThemeControl.instance.init();
ThemeControl.instance.initSystemUi();
await Permissions.instance.init();
await ContentControl.instance.init();
runApp(const ProviderScope(child: App()));
}, reportError);
Isolate.current.addErrorListener(RawReceivePort((pair) async {
final List<dynamic> errorAndStacktrace = pair;
await reportError(errorAndStacktrace.first, errorAndStacktrace.last);
}).sendPort);
FlutterError.onError = reportFlutterError;
PlatformDispatcher.instance.onError = (error, stack) {
reportError(error, stack);
return true;
};
WidgetsBinding.instance.addObserver(_WidgetsBindingObserver());

await DeviceInfoControl.instance.init();
ThemeControl.instance.init();
ThemeControl.instance.initSystemUi();
await Permissions.instance.init();
await ContentControl.instance.init();
runApp(const ProviderScope(child: App()));
}

class App extends StatefulWidget {
Expand Down
40 changes: 20 additions & 20 deletions pubspec.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 72f46e7

Please sign in to comment.