diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index ae71819..9c07841 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -3,6 +3,7 @@ plugins { id("kotlin-android") // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. id("dev.flutter.flutter-gradle-plugin") + id("com.google.gms.google-services") } android { diff --git a/android/app/google-services.json b/android/app/google-services.json new file mode 100644 index 0000000..8bf95a7 --- /dev/null +++ b/android/app/google-services.json @@ -0,0 +1,29 @@ +{ + "project_info": { + "project_number": "219079385989", + "project_id": "klimatologiot", + "storage_bucket": "klimatologiot.firebasestorage.app" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:219079385989:android:1304b7433feb658ba0daec", + "android_client_info": { + "package_name": "com.example.klimatologiot" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyAN_9rnFxG99yficqRzTKJ7751D0GC0iXA" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/android/build.gradle.kts b/android/build.gradle.kts index dbee657..5813b6d 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -1,3 +1,13 @@ +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath("com.google.gms:google-services:4.4.2") + } +} + allprojects { repositories { google() diff --git a/lib/app.dart b/lib/app.dart index 17eaef8..722bab2 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:klimatologiot/app_view.dart'; import 'package:user_repository/user_repository.dart'; import 'blocs/authentication_bloc/authentication_bloc.dart'; @@ -12,9 +13,8 @@ class MyApp extends StatelessWidget { return RepositoryProvider( create: (context) => AuthenticationBloc( userRepository: userRepository - ), - child: MyAppView(), + child: const MyAppView(), ); } } \ No newline at end of file diff --git a/lib/app_view.dart b/lib/app_view.dart index e69de29..f8e524f 100644 --- a/lib/app_view.dart +++ b/lib/app_view.dart @@ -0,0 +1,20 @@ +import 'package:flutter/material.dart'; + +class MyAppView extends StatelessWidget { + const MyAppView({super.key}); + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Klimatologi IOT', + debugShowCheckedModeBanner: false, + theme: ThemeData( + colorScheme: ColorScheme.light( + background: Colors.grey.shade100, + onBackground: Colors.black, + primary: Colors.blue, + ), + ), + ); + } +} \ No newline at end of file diff --git a/lib/blocs/authentication_bloc/authentication_bloc.dart b/lib/blocs/authentication_bloc/authentication_bloc.dart index a6af1f0..74d02c6 100644 --- a/lib/blocs/authentication_bloc/authentication_bloc.dart +++ b/lib/blocs/authentication_bloc/authentication_bloc.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:user_repository/user_repository.dart'; @@ -6,9 +8,28 @@ part 'authentication_event.dart'; part 'authentication_state.dart'; class AuthenticationBloc extends Bloc { - AuthenticationBloc() : super(AuthenticationInitial()) { - on((event, emit) { - // TODO: implement event handler + final UserRepository userRepository; + late final StreamSubscription _userSubscription; + + AuthenticationBloc({ + required this.userRepository + }) : super(const AuthenticationState.unknown()) { + _userSubscription = userRepository.user.listen((user) { + add(AuthenticationUserChanged(user)); + }); + + + on((event, emit) { + if(event.user != MyUser.empty) { + emit(AuthenticationState.authenticated(event.user!)); + } else { + emit(AuthenticationState.unauthenticated()); + } }); } + @override + Future close() { + _userSubscription.cancel(); + return super.close(); + } } diff --git a/lib/blocs/authentication_bloc/authentication_event.dart b/lib/blocs/authentication_bloc/authentication_event.dart index aad0e5a..1b96112 100644 --- a/lib/blocs/authentication_bloc/authentication_event.dart +++ b/lib/blocs/authentication_bloc/authentication_event.dart @@ -8,10 +8,7 @@ sealed class AuthenticationEvent extends Equatable { } class AuthenticationUserChanged extends AuthenticationEvent { - final MyUser user; + final MyUser? user; const AuthenticationUserChanged(this.user); - - @override - List get props => [user ?? 'no-user']; } \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 32f2fc3..5d11456 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -9,6 +9,4 @@ void main() async { await Firebase.initializeApp(); Bloc.observer = SimpleBlocObserver(); runApp(MyApp(FirebaseUserRepo())); -} - - +} \ No newline at end of file diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 804ef2f..00d0898 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -8,9 +8,11 @@ import Foundation import cloud_firestore import firebase_auth import firebase_core +import google_sign_in_ios func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTFirebaseFirestorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseFirestorePlugin")) FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin")) FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin")) + FLTGoogleSignInPlugin.register(with: registry.registrar(forPlugin: "FLTGoogleSignInPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index b53e183..3b75fe1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -184,6 +184,54 @@ packages: description: flutter source: sdk version: "0.0.0" + google_identity_services_web: + dependency: transitive + description: + name: google_identity_services_web + sha256: "5d187c46dc59e02646e10fe82665fc3884a9b71bc1c90c2b8b749316d33ee454" + url: "https://pub.dev" + source: hosted + version: "0.3.3+1" + google_sign_in: + dependency: "direct main" + description: + name: google_sign_in + sha256: "521031b65853b4409b8213c0387d57edaad7e2a949ce6dea0d8b2afc9cb29763" + url: "https://pub.dev" + source: hosted + version: "7.2.0" + google_sign_in_android: + dependency: transitive + description: + name: google_sign_in_android + sha256: "5ec98ab35387c68c0050495bb211bd88375873723a80fae7c2e9266ea0bdd8bb" + url: "https://pub.dev" + source: hosted + version: "7.2.7" + google_sign_in_ios: + dependency: transitive + description: + name: google_sign_in_ios + sha256: "234fc2830b55d1bbeb7e05662967691f5994143ff43dc70d3f139d1bbb3b8fb2" + url: "https://pub.dev" + source: hosted + version: "6.2.5" + google_sign_in_platform_interface: + dependency: transitive + description: + name: google_sign_in_platform_interface + sha256: "7f59208c42b415a3cca203571128d6f84f885fead2d5b53eb65a9e27f2965bb5" + url: "https://pub.dev" + source: hosted + version: "3.1.0" + google_sign_in_web: + dependency: transitive + description: + name: google_sign_in_web + sha256: "2fc1f941e6443b2d6984f4056a727a3eaeab15d8ee99ba7125d79029be75a1da" + url: "https://pub.dev" + source: hosted + version: "1.1.0" http: dependency: transitive description: @@ -389,5 +437,5 @@ packages: source: hosted version: "1.1.1" sdks: - dart: ">=3.8.0-0 <4.0.0" - flutter: ">=3.22.0" + dart: ">=3.9.0 <4.0.0" + flutter: ">=3.35.0" diff --git a/pubspec.yaml b/pubspec.yaml index b9c375f..c98e986 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,6 +14,7 @@ dependencies: firebase_auth: ^6.1.3 cloud_firestore: ^6.1.1 rxdart: ^0.27.7 + google_sign_in: ^7.2.0 bloc: ^8.1.0 flutter_bloc: ^8.1.0