From f8ccc798477bee488891c079f56ecc971269d8d2 Mon Sep 17 00:00:00 2001 From: Kevin ANATOLE Date: Wed, 14 Oct 2020 21:59:53 +0100 Subject: [PATCH] Basic Firebase setup --- android/app/build.gradle | 2 + android/build.gradle | 1 + lib/main.dart | 49 +++++++++++++++++- lib/views/loading.dart | 14 ++++++ pubspec.lock | 104 +++++++++++++++++++++++++++++++++++++++ pubspec.yaml | 2 + 6 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 lib/views/loading.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index b7bf74e..c94ae98 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -24,6 +24,7 @@ if (flutterVersionName == null) { 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' android { compileSdkVersion 28 @@ -60,4 +61,5 @@ flutter { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation platform('com.google.firebase:firebase-bom:25.12.0') } diff --git a/android/build.gradle b/android/build.gradle index 3100ad2..4273368 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -8,6 +8,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.5.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath 'com.google.gms:google-services:4.3.3' } } diff --git a/lib/main.dart b/lib/main.dart index f86fd99..68bc43f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,14 +1,59 @@ import 'package:commander_league/views/home.dart'; +import 'package:commander_league/views/loading.dart'; import 'package:flutter/material.dart'; +// Import the firebase_core plugin +import 'package:firebase_core/firebase_core.dart'; + void main() { runApp(MyApp()); } -class MyApp extends StatelessWidget { - // This widget is the root of your application. +class MyApp extends StatefulWidget { + @override + _MyAppState createState() => _MyAppState(); +} + +class _MyAppState extends State { + // Set default `_initialized` and `_error` state to false + bool _initialized = false; + bool _error = false; + + // Define an async function to initialize FlutterFire + void initializeFlutterFire() async { + try { + // Wait for Firebase to initialize and set `_initialized` state to true + await Firebase.initializeApp(); + setState(() { + _initialized = true; + }); + } catch (e) { + // Set `_error` state to true if Firebase initialization fails + print(e); + setState(() { + _error = true; + }); + } + } + + @override + void initState() { + initializeFlutterFire(); + super.initState(); + } + @override Widget build(BuildContext context) { + // Show error message if initialization failed + if (_error) { + return Loading(); + } + + // Show a loader until FlutterFire is initialized + if (!_initialized) { + return Loading(); + } + return MaterialApp( title: 'Commander League', theme: ThemeData( diff --git a/lib/views/loading.dart b/lib/views/loading.dart new file mode 100644 index 0000000..26961eb --- /dev/null +++ b/lib/views/loading.dart @@ -0,0 +1,14 @@ +import 'package:flutter/material.dart'; + +class Loading extends StatelessWidget { + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + body: SafeArea( + child: Center(child: CircularProgressIndicator()), + ), + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index ea61056..881f82a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -57,6 +57,55 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + firebase: + dependency: transitive + description: + name: firebase + url: "https://pub.dartlang.org" + source: hosted + version: "7.3.1" + firebase_auth: + dependency: "direct main" + description: + name: firebase_auth + url: "https://pub.dartlang.org" + source: hosted + version: "0.18.1+2" + firebase_auth_platform_interface: + dependency: transitive + description: + name: firebase_auth_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + firebase_auth_web: + dependency: transitive + description: + name: firebase_auth_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.1+1" + firebase_core: + dependency: "direct main" + description: + name: firebase_core + url: "https://pub.dartlang.org" + source: hosted + version: "0.5.0+1" + firebase_core_platform_interface: + dependency: transitive + description: + name: firebase_core_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + firebase_core_web: + dependency: transitive + description: + name: firebase_core_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" flutter: dependency: "direct main" description: flutter @@ -67,6 +116,39 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + http: + dependency: transitive + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.2" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.4" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.1" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.2" matcher: dependency: transitive description: @@ -88,6 +170,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.7.0" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" + quiver: + dependency: transitive + description: + name: quiver + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" sky_engine: dependency: transitive description: flutter @@ -151,3 +254,4 @@ packages: version: "2.0.8" sdks: dart: ">=2.9.0-14.0.dev <3.0.0" + flutter: ">=1.12.13+hotfix.5 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 0b75e51..5670f76 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,6 +23,8 @@ environment: dependencies: flutter: sdk: flutter + firebase_core: "^0.5.0+1" + firebase_auth: "^0.18.1+2" # The following adds the Cupertino Icons font to your application.