mirror of
https://github.com/timokz/flutter-vienna-hackathon-25.git
synced 2025-11-08 19:04:20 +01:00
30 lines
664 B
Dart
30 lines
664 B
Dart
import 'package:google_sign_in/google_sign_in.dart';
|
|
|
|
class AuthService {
|
|
static final _google = GoogleSignIn.instance;
|
|
|
|
static AuthService? _instance;
|
|
|
|
AuthService._() {
|
|
_google.initialize();
|
|
}
|
|
factory AuthService() {
|
|
if (_instance != null) return _instance!;
|
|
_instance = AuthService._();
|
|
|
|
return _instance!;
|
|
}
|
|
|
|
static Stream<GoogleSignInAuthenticationEvent?> get onUserChanged =>
|
|
_google.authenticationEvents;
|
|
|
|
static Future<GoogleSignInAccount?> signIn() async {
|
|
try {
|
|
return await _google.authenticate();
|
|
} catch (_) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
static Future<void> signOut() => _google.disconnect();
|
|
}
|