[英]Setting Up Firebase For Flutter
I been settling up the project on Firebase. The app has been set up for iOS and Android. It works fine for Flutter Run but it doesn't connect to Firebase我一直在 Firebase 上设置项目。该应用程序已为 iOS 和 Android 设置。它适用于 Flutter 运行但它没有连接到 Firebase
The code in Main.dart is as followed Main.dart中的代码如下
import 'package:flutter/material.dart';import 'package:footballcrazyquiz/routes.dart';import 'package:footballcrazyquiz/theme.dart';import 'package:firebase_core/firebase_core.dart';import 'package:provider/provider.dart';import 'package:footballcrazyquiz/shared/shared.dart';import 'package:footballcrazyquiz/services/services.dart';
void main() {WidgetsFlutterBinding.ensureInitialized();runApp(const App());}
class App extends StatefulWidget {const App({super.key});
@overrideState<App> createState() => _AppState();}class _AppState extends State<App> {final Future<FirebaseApp> _initialization = Firebase.initializeApp();
@overrideWidget build(BuildContext context) {return FutureBuilder(// Initialize FlutterFire:future: _initialization,builder: (context, snapshot) {// Check for errorsif (snapshot.hasError) {
}
// Once complete, show your application
if (snapshot.connectionState == ConnectionState.done) {
return StreamProvider(
create: (_) => FirestoreService().streamReport(),
catchError: (_, err) => Report(),
initialData: Report(),
child: MaterialApp(
debugShowCheckedModeBanner: true,
routes: appRoutes,
theme: appTheme
),
);
}
// Otherwise, show something whilst waiting for initialization to complete
return const MaterialApp(home: LoadingScreen());
},
);
}}
I'm also not able to generate Android Signing In report in terminal, which I need for SHA 1. Exception is in Android/app/build.gradle line 28 and that's as followed我也无法在终端中生成 Android 登录报告,我需要 SHA 1。异常在 Android/app/build.gradle 第 28 行,如下所示
def localProperties = new Properties()def localPropertiesFile = rootProject.file('local.properties')if (localPropertiesFile.exists()) {localPropertiesFile.withReader('UTF-8') { reader ->localProperties.load(reader)}}
def flutterRoot = localProperties.getProperty('flutter.sdk')if (flutterRoot == null) {throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')if (flutterVersionCode == null) {flutterVersionCode = '1'}
def flutterVersionName = localProperties.getProperty('flutter.versionName')if (flutterVersionName == null) {flutterVersionName = '1.0'}
apply plugin: 'com.android.application'apply plugin: 'kotlin-android'apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {compileSdkVersion flutter.compileSdkVersionndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "io.eddiegamble.footballcrazyquiz"
minSdkVersion 19
targetSdkVersion 31.0.1
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multidex true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {source '../..'}
dependencies {implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"implementation 'com.android.support:multidex:1.0.3'implementation platform('com.google.firebase:firebase-bom:31.1.0')implementation 'com.google.firebase:firebase-analytics'}apply plugin: 'com.google.gms.google-services'
Thank you for reading感谢您阅读
Try the following:尝试以下操作:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.