-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
344 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:get/get.dart'; | ||
|
||
import 'package:app_filmes/repositories/login/login_repository_impl.dart'; | ||
import 'package:app_filmes/repositories/login/login_repository.dart'; | ||
import 'package:app_filmes/services/login/login_service.dart'; | ||
import 'package:app_filmes/services/login/login_service_impl.dart'; | ||
|
||
class ApplicationBindings implements Bindings { | ||
@override | ||
void dependencies() { | ||
Get.lazyPut<LoginRepository>( | ||
() => LoginRepositoryImpl(), | ||
fenix: true, | ||
); | ||
Get.lazyPut<LoginService>( | ||
() => LoginServiceImpl( | ||
loginRepository: Get.find(), | ||
), | ||
fenix: true, | ||
); | ||
} | ||
} |
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,23 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:get/get.dart'; | ||
|
||
mixin LoaderMixin on GetxController { | ||
void loaderListener(RxBool loaderRx) { | ||
ever<bool>( | ||
loaderRx, | ||
(loading) async { | ||
if (loading) { | ||
await Get.dialog( | ||
const Center( | ||
child: CircularProgressIndicator(), | ||
), | ||
barrierDismissible: false, | ||
); | ||
} else { | ||
Get.back(); | ||
} | ||
}, | ||
); | ||
} | ||
} |
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,58 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:get/get.dart'; | ||
|
||
mixin MessagesMixin on GetxController { | ||
void messageListener(Rxn<MessageModel> message) { | ||
ever<MessageModel?>( | ||
message, | ||
(model) { | ||
if (model != null) { | ||
Get.snackbar( | ||
model.title, | ||
model.message, | ||
backgroundColor: model.type.color(), | ||
); | ||
} | ||
}, | ||
); | ||
} | ||
} | ||
|
||
class MessageModel { | ||
final String title; | ||
final String message; | ||
final MessageType type; | ||
|
||
MessageModel({ | ||
required this.title, | ||
required this.message, | ||
required this.type, | ||
}); | ||
|
||
MessageModel.error({ | ||
required this.title, | ||
required this.message, | ||
}) : type = MessageType.error; | ||
|
||
MessageModel.info({ | ||
required this.title, | ||
required this.message, | ||
}) : type = MessageType.info; | ||
} | ||
|
||
enum MessageType { | ||
error, | ||
info, | ||
} | ||
|
||
extension MessageTypeExtension on MessageType { | ||
Color color() { | ||
switch (this) { | ||
case MessageType.error: | ||
return Colors.red[600] ?? Colors.red; | ||
case MessageType.info: | ||
return Colors.blue[200] ?? Colors.blue; | ||
} | ||
} | ||
} |
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,14 @@ | ||
import 'package:get/get.dart'; | ||
|
||
import 'login_controller.dart'; | ||
|
||
class LoginBindings implements Bindings { | ||
@override | ||
void dependencies() { | ||
Get.lazyPut( | ||
() => LoginController( | ||
loginService: Get.find(), | ||
), | ||
); | ||
} | ||
} |
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,44 @@ | ||
import 'package:get/get.dart'; | ||
|
||
import 'package:app_filmes/services/login/login_service.dart'; | ||
import 'package:app_filmes/application/ui/loader/loader_mixin.dart'; | ||
import 'package:app_filmes/application/ui/messages/messages_mixin.dart'; | ||
|
||
class LoginController extends GetxController with LoaderMixin, MessagesMixin { | ||
final LoginService _loginService; | ||
final loading = false.obs; | ||
final message = Rxn<MessageModel>(); | ||
|
||
LoginController({ | ||
required LoginService loginService, | ||
}) : _loginService = loginService; | ||
|
||
@override | ||
void onInit() { | ||
super.onInit(); | ||
loaderListener(loading); | ||
messageListener(message); | ||
} | ||
|
||
Future<void> login() async { | ||
try { | ||
loading(true); | ||
await _loginService.login(); | ||
loading(false); | ||
message( | ||
MessageModel.info( | ||
title: 'Success', | ||
message: 'Login with Success', | ||
), | ||
); | ||
} catch (e, s) { | ||
print(e); | ||
print(s); | ||
loading(false); | ||
MessageModel.error( | ||
title: 'Error', | ||
message: 'Login with Error', | ||
); | ||
} | ||
} | ||
} |
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,16 @@ | ||
import 'package:get/get.dart'; | ||
|
||
import 'package:app_filmes/application/modules/module.dart'; | ||
import 'login_bindings.dart'; | ||
import 'login_page.dart'; | ||
|
||
class LoginModule implements Module { | ||
@override | ||
List<GetPage> routers = [ | ||
GetPage( | ||
name: '/login', | ||
page: () => const LoginPage(), | ||
binding: LoginBindings(), | ||
) | ||
]; | ||
} |
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,49 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:flutter_signin_button/flutter_signin_button.dart'; | ||
import 'package:get/get.dart'; | ||
|
||
import 'login_controller.dart'; | ||
|
||
class LoginPage extends GetView<LoginController> { | ||
const LoginPage({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Stack( | ||
alignment: Alignment.topCenter, | ||
children: [ | ||
Image.asset( | ||
'assets/images/background.png', | ||
width: Get.width, | ||
height: Get.height, | ||
fit: BoxFit.cover, | ||
), | ||
Container(color: Colors.black45), | ||
Padding( | ||
padding: const EdgeInsets.only(top: 80), | ||
child: Column( | ||
children: [ | ||
Image.asset('assets/images/logo.png'), | ||
const SizedBox(height: 50), | ||
SizedBox( | ||
width: Get.width * .9, | ||
height: 42, | ||
child: SignInButton( | ||
Buttons.Google, | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(100), | ||
), | ||
text: 'Entrar com o Google', | ||
onPressed: () => controller.login(), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
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,12 @@ | ||
import 'package:get/get.dart'; | ||
|
||
import 'splash_controller.dart'; | ||
|
||
class SplashBindings implements Bindings { | ||
@override | ||
void dependencies() { | ||
Get.put( | ||
SplashController(), | ||
); | ||
} | ||
} |
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,3 +1,9 @@ | ||
import 'package:get/get.dart'; | ||
|
||
class SplashController extends GetxController {} | ||
class SplashController extends GetxController { | ||
@override | ||
void onReady() { | ||
super.onReady(); | ||
Get.offAllNamed('/login'); | ||
} | ||
} |
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,5 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
|
||
abstract class LoginRepository { | ||
Future<UserCredential> login(); | ||
} |
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,22 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:google_sign_in/google_sign_in.dart'; | ||
|
||
import 'login_repository.dart'; | ||
|
||
class LoginRepositoryImpl implements LoginRepository { | ||
@override | ||
// ignore: override_on_non_overriding_member | ||
Future<UserCredential> login() async { | ||
final googleUser = await GoogleSignIn().signIn(); | ||
final googleAuth = await googleUser?.authentication; | ||
|
||
if (googleAuth != null) { | ||
final credential = GoogleAuthProvider.credential( | ||
accessToken: googleAuth.accessToken, | ||
idToken: googleAuth.idToken, | ||
); | ||
return FirebaseAuth.instance.signInWithCredential(credential); | ||
} | ||
throw Exception('Erro ao realizar login com 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
|
||
abstract class LoginService { | ||
Future<UserCredential> login(); | ||
} |
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,15 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
|
||
import 'package:app_filmes/repositories/login/login_repository.dart'; | ||
import 'login_service.dart'; | ||
|
||
class LoginServiceImpl implements LoginService { | ||
final LoginRepository _loginRepository; | ||
|
||
LoginServiceImpl({ | ||
required LoginRepository loginRepository, | ||
}) : _loginRepository = loginRepository; | ||
|
||
@override | ||
Future<UserCredential> login() => _loginRepository.login(); | ||
} |
Oops, something went wrong.