From ff0c62c985c3992d7124162566f52e24ba1edc0b Mon Sep 17 00:00:00 2001 From: Marcelo Pecin Date: Sat, 26 Nov 2022 22:36:34 +0100 Subject: [PATCH] fix(login): ajustado o fluxo de login --- README.md | 2 + lib/src/app.dart | 6 +- lib/src/ui/layouts/tab.dart | 16 ++- lib/src/ui/pages/login.dart | 188 ++++++++++++++++++------------------ 4 files changed, 106 insertions(+), 106 deletions(-) diff --git a/README.md b/README.md index ad5effd..2420ccc 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/src/app.dart b/lib/src/app.dart index 8a695cd..c960684 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -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}); @@ -37,10 +36,7 @@ class App extends StatelessWidget { selectionColor: Colors.grey.shade300, ), ), - home: Consumer( - builder: (context, user, _) => - user.loggedIn ? const TabLayout() : const LoginPage(), - ), + home: const TabLayout(), ), ); } diff --git a/lib/src/ui/layouts/tab.dart b/lib/src/ui/layouts/tab.dart index f6a2432..0f43d9d 100644 --- a/lib/src/ui/layouts/tab.dart +++ b/lib/src/ui/layouts/tab.dart @@ -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'; @@ -16,11 +19,14 @@ class TabLayout extends StatefulWidget { class _TabLayoutState extends State { int _currentPage = 0; - static const List _pages = [ - HomePage(), - RecentsPage(), - FavoritesPage(), - ProfilePage(), + static final List _pages = [ + const HomePage(), + const RecentsPage(), + const FavoritesPage(), + Consumer( + builder: (context, provider, _) => + provider.loggedIn ? const ProfilePage() : const LoginPage(), + ), ]; void _onItemTapped(int index) { diff --git a/lib/src/ui/pages/login.dart b/lib/src/ui/pages/login.dart index 7d892e1..01c1ea6 100644 --- a/lib/src/ui/pages/login.dart +++ b/lib/src/ui/pages/login.dart @@ -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 { @@ -21,118 +20,115 @@ class _LoginPageState extends State { @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( - builder: (context, provider, _) => ElevatedButton( - style: ButtonStyle( - elevation: MaterialStateProperty.all(0.0), - backgroundColor: MaterialStateProperty.all( - AppColors.primaryColor.withOpacity( - provider.isLoading ? 0.5 : 1.0, - ), - ), - foregroundColor: MaterialStateProperty.all( - Colors.white, + ), + ], + ), + const SizedBox(height: 30.0), + Consumer( + builder: (context, provider, _) => ElevatedButton( + style: ButtonStyle( + elevation: MaterialStateProperty.all(0.0), + backgroundColor: MaterialStateProperty.all( + AppColors.primaryColor.withOpacity( + provider.isLoading ? 0.5 : 1.0, ), - shape: MaterialStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular(4.0), - ), + ), + foregroundColor: MaterialStateProperty.all( + Colors.white, + ), + shape: MaterialStateProperty.all( + 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( - 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( + AppColors.primaryColor, ), - onPressed: () => Navigation.push(context, RegisterPage()), - child: const Text('Criar cadastro'), ), - ], - ), - ], - ), + onPressed: () => Navigation.push(context, RegisterPage()), + child: const Text('Criar cadastro'), + ), + ], + ), + ], ), ), ),