-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/menyalaAbangkuuuu/spotify_c…
- Loading branch information
Showing
11 changed files
with
274 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
import 'package:spotify_clone/screens/home/home_screen.dart'; | ||
import 'package:spotify_clone/services/auth_service.dart'; | ||
|
||
class LoginScreen extends StatefulWidget { | ||
static const routeName = '/login'; | ||
const LoginScreen({super.key}); | ||
|
||
@override | ||
State<LoginScreen> createState() => _LoginScreenState(); | ||
} | ||
|
||
class _LoginScreenState extends State<LoginScreen> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Center( | ||
child: ElevatedButton( | ||
onPressed: () async { | ||
final user = await AuthService.logInWithGoogle(); | ||
if (user.user != null) { | ||
context.go(MyHomePage.routeName); | ||
} | ||
}, | ||
child: Text('Login with google')), | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,29 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
import 'package:spotify_clone/screens/login/login_screen.dart'; | ||
|
||
AppBar searchAppBar(BuildContext context) { | ||
final user = FirebaseAuth.instance.currentUser; | ||
|
||
return AppBar( | ||
automaticallyImplyLeading: false, | ||
title: const Text( | ||
'Search', | ||
style: TextStyle( | ||
fontWeight: FontWeight.bold, | ||
automaticallyImplyLeading: false, | ||
title: const Text( | ||
'Search', | ||
style: TextStyle( | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
), | ||
centerTitle: false, | ||
leading: const IconButton( | ||
icon: Icon(Icons.person), | ||
onPressed: null, | ||
), | ||
); | ||
centerTitle: false, | ||
leading: CircleAvatar( | ||
radius: 10, | ||
child: user?.photoURL != null | ||
? ClipOval( | ||
child: Image.network( | ||
user!.photoURL!, | ||
fit: BoxFit.cover, | ||
), | ||
) | ||
: const Icon(Icons.person), | ||
)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:google_sign_in/google_sign_in.dart'; | ||
|
||
const List<String> scopes = <String>[ | ||
'email', | ||
'https://www.googleapis.com/auth/contacts.readonly', | ||
]; | ||
|
||
class AuthService { | ||
static Future<UserCredential> logInWithGoogle() async { | ||
final GoogleSignIn googleSignIn = GoogleSignIn( | ||
scopes: scopes, | ||
); | ||
// Trigger the authentication flow | ||
final GoogleSignInAccount? googleUser = await googleSignIn.signIn(); | ||
|
||
// Obtain the auth details from the request | ||
final GoogleSignInAuthentication? googleAuth = | ||
await googleUser?.authentication; | ||
|
||
// Create a new credential | ||
final credential = GoogleAuthProvider.credential( | ||
accessToken: googleAuth?.accessToken, | ||
idToken: googleAuth?.idToken, | ||
); | ||
|
||
// Once signed in, return the UserCredential | ||
return await FirebaseAuth.instance.signInWithCredential(credential); | ||
} | ||
} |
Oops, something went wrong.