diff --git a/lib/presentation/login/bloc/login_bloc.dart b/lib/presentation/login/bloc/login_bloc.dart index 6cbf7d88..6f2ca76e 100644 --- a/lib/presentation/login/bloc/login_bloc.dart +++ b/lib/presentation/login/bloc/login_bloc.dart @@ -29,8 +29,6 @@ class LoginBloc extends Bloc { if (!state.isFormFilled()) return; emit(state.copyWith( - isPasswordFocused: false, - isUsernameFocused: false, status: const Status.loading(), )); @@ -84,18 +82,10 @@ class LoginBloc extends Bloc { } void _updatePasswordInput(PasswordInput event, Emitter emit) { - emit(state.copyWith( - isPasswordFocused: true, - isUsernameFocused: false, - password: event.value, - )); + emit(state.copyWith(password: event.value)); } void _updateUsernameInput(UsernameInput event, Emitter emit) { - emit(state.copyWith( - isUsernameFocused: true, - isPasswordFocused: false, - username: event.value, - )); + emit(state.copyWith(username: event.value)); } } diff --git a/lib/presentation/login/bloc/login_state.dart b/lib/presentation/login/bloc/login_state.dart index 019724c3..a43298d4 100644 --- a/lib/presentation/login/bloc/login_state.dart +++ b/lib/presentation/login/bloc/login_state.dart @@ -6,12 +6,6 @@ part of 'login_bloc.dart'; class LoginState with _$LoginState { /// State class for [LoginBloc]. const factory LoginState({ - /// Whether the username field is in focus. - @Default(false) bool isUsernameFocused, - - /// Whether the password field is in focus. - @Default(false) bool isPasswordFocused, - /// Whether the password field should be obscured. @Default(true) bool obscurePassword, diff --git a/lib/presentation/login/widgets/background_decoration.dart b/lib/presentation/login/widgets/background_decoration.dart index a168eaf8..ba059f2d 100644 --- a/lib/presentation/login/widgets/background_decoration.dart +++ b/lib/presentation/login/widgets/background_decoration.dart @@ -15,7 +15,7 @@ class BackgroundDecoration extends StatelessWidget { Positioned( top: 0, left: 0, - child: SvgPicture.asset( + child: svg.SvgPicture.asset( AppAssets.circle1, width: 170.r, ), @@ -23,7 +23,7 @@ class BackgroundDecoration extends StatelessWidget { Positioned( top: 80.r, right: 0, - child: SvgPicture.asset( + child: svg.SvgPicture.asset( AppAssets.triangle, width: 140.r, ), diff --git a/lib/presentation/login/widgets/login_widgets.dart b/lib/presentation/login/widgets/login_widgets.dart index c3da7f39..c0757c35 100644 --- a/lib/presentation/login/widgets/login_widgets.dart +++ b/lib/presentation/login/widgets/login_widgets.dart @@ -2,7 +2,8 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:flutter_svg/flutter_svg.dart'; +import 'package:flutter_svg/flutter_svg.dart' as svg; +import 'package:flutter_svg_provider/flutter_svg_provider.dart'; import 'package:get/get.dart'; import '../../../data/constants/assets.dart'; diff --git a/lib/presentation/login/widgets/text_fields.dart b/lib/presentation/login/widgets/text_fields.dart index 239b0286..9a38cc58 100644 --- a/lib/presentation/login/widgets/text_fields.dart +++ b/lib/presentation/login/widgets/text_fields.dart @@ -7,45 +7,35 @@ class PasswordField extends StatelessWidget { @override Widget build(BuildContext context) { - // [BlocSelector] is not used because widget depends on both - // [state.isPasswordFocused] and [state.obscurePassword]. - return BlocBuilder( - builder: (context, state) { - return Stack( - alignment: Alignment.centerRight, - children: [ - TextInput( - action: TextInputAction.done, - hint: 'Password', - keyboard: TextInputType.visiblePassword, - obscureText: state.obscurePassword, - onChanged: (value) => - context.read().add(PasswordInput(value)), - prefix: Padding( - padding: EdgeInsets.symmetric( - horizontal: 8.r, - vertical: 10.r, - ), - child: SvgPicture.asset( - AppAssets.lock, - // TODO(BURG3R5): Deal with Focus transfer. - color: (state.isPasswordFocused) - ? AppColors.primary - : AppColors.grey1, - ), - ), + return BlocSelector( + selector: (state) => state.obscurePassword, + builder: (context, obscurePassword) { + return TextInput( + action: TextInputAction.done, + hint: 'Password', + keyboard: TextInputType.visiblePassword, + obscureText: obscurePassword, + onChanged: (value) => + context.read().add(PasswordInput(value)), + prefix: Padding( + padding: EdgeInsets.symmetric( + horizontal: 8.r, + vertical: 10.r, + ), + // TODO(BURG3R5): Deal with Focus transfer. + child: const ImageIcon( + Svg(AppAssets.lock), ), - IconButton( - icon: SvgPicture.asset( - (state.obscurePassword) ? AppAssets.eyeOff : AppAssets.eyeOn, - color: state.isPasswordFocused - ? AppColors.primary - : AppColors.grey1, + ), + suffix: IconButton( + icon: ImageIcon( + Svg( + obscurePassword ? AppAssets.eyeOff : AppAssets.eyeOn, ), - onPressed: () => - context.read().add(const ToggleObscure()), ), - ], + onPressed: () => + context.read().add(const ToggleObscure()), + ), ); }, ); @@ -59,25 +49,18 @@ class UsernameField extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocSelector( - selector: (state) => state.isUsernameFocused, - builder: (context, isUsernameFocused) { - return TextInput( - hint: 'Username', - onChanged: (value) => - context.read().add(UsernameInput(value)), - prefix: Padding( - padding: EdgeInsets.symmetric( - horizontal: 8.r, - vertical: 10.r, - ), - child: SvgPicture.asset( - AppAssets.person, - color: isUsernameFocused ? AppColors.primary : AppColors.grey1, - ), - ), - ); - }, + return TextInput( + hint: 'Username', + onChanged: (value) => context.read().add(UsernameInput(value)), + prefix: Padding( + padding: EdgeInsets.symmetric( + horizontal: 8.r, + vertical: 10.r, + ), + child: const ImageIcon( + Svg(AppAssets.person), + ), + ), ); } } diff --git a/test/presentation/login/login_test.dart b/test/presentation/login/login_test.dart index 70404c17..280b00ea 100644 --- a/test/presentation/login/login_test.dart +++ b/test/presentation/login/login_test.dart @@ -14,8 +14,6 @@ void blocTests() { bloc.state, const LoginState( rememberMe: true, - isUsernameFocused: false, - isPasswordFocused: false, obscurePassword: true, showDialog: false, status: Status(), @@ -60,9 +58,7 @@ void blocTests() { ..add(const PasswordInput('')) ..add(const UsernameInput('A')), expect: () => const [ - LoginState(isUsernameFocused: true), - LoginState(isPasswordFocused: true), - LoginState(isUsernameFocused: true, username: 'A'), + LoginState(username: 'A'), ], ); @@ -75,12 +71,10 @@ void blocTests() { expect: () => const [ LoginState( username: 'username', - isUsernameFocused: true, ), LoginState( username: 'username', password: 'password', - isPasswordFocused: true, ), ], );