Skip to content

Commit

Permalink
Merge pull request #27 from avuenja/24-ajustar-fluxo-de-login
Browse files Browse the repository at this point in the history
fix(login): ajustado o fluxo de login
  • Loading branch information
avuenja authored Nov 26, 2022
2 parents aac7933 + ff0c62c commit ec85fc4
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 106 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ O projeto utiliza a especificação de [Conventional Commits](https://www.conven
O sistema foi configurado com o [lefthook](https://github.com/evilmartians/lefthook), e adiconado as configurações em `lefthook.yml` e criado as configurações das mensagens em `bin/commit_message.dart`.

## Contribuidores

Acesse a página de [Insights](https://github.com/avuenja/tabnews-app/graphs/contributors) do projeto.
6 changes: 1 addition & 5 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:tabnews/src/constants.dart';
import 'package:tabnews/src/providers/content.dart';
import 'package:tabnews/src/providers/user.dart';
import 'package:tabnews/src/ui/layouts/tab.dart';
import 'package:tabnews/src/ui/pages/login.dart';

class App extends StatelessWidget {
const App({super.key});
Expand Down Expand Up @@ -37,10 +36,7 @@ class App extends StatelessWidget {
selectionColor: Colors.grey.shade300,
),
),
home: Consumer<UserProvider>(
builder: (context, user, _) =>
user.loggedIn ? const TabLayout() : const LoginPage(),
),
home: const TabLayout(),
),
);
}
Expand Down
16 changes: 11 additions & 5 deletions lib/src/ui/layouts/tab.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:tabnews/src/providers/user.dart';

import 'package:tabnews/src/ui/pages/favorites.dart';
import 'package:tabnews/src/ui/pages/home.dart';
import 'package:tabnews/src/ui/pages/login.dart';
import 'package:tabnews/src/ui/pages/profile.dart';
import 'package:tabnews/src/ui/pages/recents.dart';
import 'package:tabnews/src/ui/widgets/bottom_bar.dart';
Expand All @@ -16,11 +19,14 @@ class TabLayout extends StatefulWidget {

class _TabLayoutState extends State<TabLayout> {
int _currentPage = 0;
static const List<Widget> _pages = [
HomePage(),
RecentsPage(),
FavoritesPage(),
ProfilePage(),
static final List<Widget> _pages = [
const HomePage(),
const RecentsPage(),
const FavoritesPage(),
Consumer<UserProvider>(
builder: (context, provider, _) =>
provider.loggedIn ? const ProfilePage() : const LoginPage(),
),
];

void _onItemTapped(int index) {
Expand Down
188 changes: 92 additions & 96 deletions lib/src/ui/pages/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:provider/provider.dart';
import 'package:tabnews/src/constants.dart';
import 'package:tabnews/src/providers/user.dart';
import 'package:tabnews/src/ui/pages/register.dart';
import 'package:tabnews/src/ui/widgets/top_bar.dart';
import 'package:tabnews/src/utils/navigation.dart';

class LoginPage extends StatefulWidget {
Expand All @@ -21,118 +20,115 @@ class _LoginPageState extends State<LoginPage> {

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const AppTopBar(),
body: Center(
child: Form(
key: _formKey,
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
Expanded(
child: TextFormField(
keyboardType: TextInputType.emailAddress,
cursorColor: AppColors.primaryColor,
decoration: const InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors.primaryColor,
width: 2.0,
),
return Center(
child: Form(
key: _formKey,
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
Expanded(
child: TextFormField(
keyboardType: TextInputType.emailAddress,
cursorColor: AppColors.primaryColor,
decoration: const InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors.primaryColor,
width: 2.0,
),
hintText: 'Email',
),
controller: emailTextController,
hintText: 'Email',
),
controller: emailTextController,
),
],
),
Row(
children: [
Expanded(
child: TextFormField(
enableSuggestions: false,
autocorrect: false,
obscureText: true,
cursorColor: AppColors.primaryColor,
decoration: const InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors.primaryColor,
width: 2.0,
),
),
],
),
Row(
children: [
Expanded(
child: TextFormField(
enableSuggestions: false,
autocorrect: false,
obscureText: true,
cursorColor: AppColors.primaryColor,
decoration: const InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors.primaryColor,
width: 2.0,
),
hintText: 'Senha',
),
controller: passwordTextController,
hintText: 'Senha',
),
controller: passwordTextController,
),
],
),
const SizedBox(height: 30.0),
Consumer<UserProvider>(
builder: (context, provider, _) => ElevatedButton(
style: ButtonStyle(
elevation: MaterialStateProperty.all<double>(0.0),
backgroundColor: MaterialStateProperty.all<Color>(
AppColors.primaryColor.withOpacity(
provider.isLoading ? 0.5 : 1.0,
),
),
foregroundColor: MaterialStateProperty.all<Color>(
Colors.white,
),
],
),
const SizedBox(height: 30.0),
Consumer<UserProvider>(
builder: (context, provider, _) => ElevatedButton(
style: ButtonStyle(
elevation: MaterialStateProperty.all<double>(0.0),
backgroundColor: MaterialStateProperty.all<Color>(
AppColors.primaryColor.withOpacity(
provider.isLoading ? 0.5 : 1.0,
),
shape: MaterialStateProperty.all<OutlinedBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4.0),
),
),
foregroundColor: MaterialStateProperty.all<Color>(
Colors.white,
),
shape: MaterialStateProperty.all<OutlinedBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4.0),
),
),
onPressed: provider.isLoading
? null
: () {
if (emailTextController.text.isEmpty ||
passwordTextController.text.isEmpty) {
return;
}
),
onPressed: provider.isLoading
? null
: () {
if (emailTextController.text.isEmpty ||
passwordTextController.text.isEmpty) {
return;
}

provider.login(
emailTextController.text,
passwordTextController.text,
);
},
child: Text(
provider.isLoading ? 'Aguarde...' : 'Login',
style: const TextStyle().copyWith(
fontSize: 16.0,
),
provider.login(
emailTextController.text,
passwordTextController.text,
);
},
child: Text(
provider.isLoading ? 'Aguarde...' : 'Login',
style: const TextStyle().copyWith(
fontSize: 16.0,
),
),
),
const SizedBox(height: 30.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text('Ainda não possui conta?'),
TextButton(
style: const ButtonStyle().copyWith(
foregroundColor: MaterialStateProperty.all<Color>(
AppColors.primaryColor,
),
),
const SizedBox(height: 30.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text('Ainda não possui conta?'),
TextButton(
style: const ButtonStyle().copyWith(
foregroundColor: MaterialStateProperty.all<Color>(
AppColors.primaryColor,
),
onPressed: () => Navigation.push(context, RegisterPage()),
child: const Text('Criar cadastro'),
),
],
),
],
),
onPressed: () => Navigation.push(context, RegisterPage()),
child: const Text('Criar cadastro'),
),
],
),
],
),
),
),
Expand Down

0 comments on commit ec85fc4

Please sign in to comment.