Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Adiciona forma de autenticação com o Google (#58) #41

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/images/Google.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 39 additions & 26 deletions lib/ui/login/view/LoginView.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'package:aranduapp/core/log/Log.dart';
import 'package:aranduapp/ui/home/view/HomeView.dart';
import 'package:aranduapp/ui/shared/TextAndLink.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

import 'package:aranduapp/ui/login/viewModel/LoginViewModel.dart';

Expand All @@ -15,6 +13,7 @@ import 'package:aranduapp/ui/shared/TextEmail.dart';
import 'package:aranduapp/ui/shared/ErrorPopUp.dart';
import 'package:aranduapp/ui/shared/TextPassword.dart';
import 'package:aranduapp/ui/shared/OrDivider.dart';
import 'package:url_launcher/url_launcher.dart';

class Login extends StatelessWidget {
const Login({super.key});
Expand All @@ -37,6 +36,40 @@ class _Login extends StatefulWidget {
}
}

class GoogleLoginButton extends StatelessWidget {
const GoogleLoginButton({super.key});

Future<void> _launchGoogleSignIn() async {
final Uri url = Uri.parse('http://localhost/auth/google');
if (!await launchUrl(url, mode: LaunchMode.externalApplication)) {
throw Exception('Não foi possível abrir a URL: $url');
}
}

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: _launchGoogleSignIn,
child: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
border: Border.all(color: Theme.of(context).colorScheme.outline),
color: Colors.transparent,
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Image.asset(
'assets/images/Google.png',
fit: BoxFit.cover,
),
),
),
);
}
}

class _LoginState extends State<_Login> {
late Future<void> _future;

Expand Down Expand Up @@ -116,10 +149,10 @@ class _LoginState extends State<_Login> {
const SizedBox(height: 80),
_loginButtonSection(),
const OrDivider(),
_loggingInWithOther(),
const GoogleLoginButton(),
TextAndLink(
text: 'É novo pro aqui?',
link: 'Cria a sua conta',
text: 'Não tem uma conta?',
link: 'Registre-se',
action: () {
Navigator.of(context).push(
MaterialPageRoute(
Expand Down Expand Up @@ -154,7 +187,7 @@ class _LoginState extends State<_Login> {
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => RecoverAccount(),
builder: (context) => RecoverAccount(),
),
);
},
Expand Down Expand Up @@ -201,24 +234,4 @@ class _LoginState extends State<_Login> {
)),
);
}

Widget _loggingInWithOther() {
return GestureDetector(
onTap: () => Log.d(""),
child: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Theme.of(context).colorScheme.outline),
color: Colors.transparent,
),
child: Icon(
FontAwesomeIcons.google,
size: 20,
color: Theme.of(context).colorScheme.primary,
),
),
);
}
}
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ dependencies:
dio: ^5.7.0
font_awesome_flutter: ^10.8.0
flutter_secure_storage: ^9.2.2
url_launcher: ^6.2.1


dev_dependencies:
flutter_test:
Expand Down Expand Up @@ -71,6 +73,7 @@ flutter:
- assets/images/Component1.png
- assets/images/Component2.png
- assets/images/Component3.png
- assets/images/Google.png

# To add assets to your application, add an assets section, like this:
# assets:
Expand Down
Loading