-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: text_filed widgets page independent (#648)
* refactor: change widgets folders from voices_[name] to just [name] to be consistent * refactor: Introduce VoicesTextField which is page independent and LoginXTextField which are tied to LoginBloc * fix: voices_x_text_field child widget reference
- Loading branch information
1 parent
a729823
commit 64e5a80
Showing
22 changed files
with
202 additions
and
96 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
29 changes: 29 additions & 0 deletions
29
catalyst_voices/lib/pages/login/login_email_text_filed.dart
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,29 @@ | ||
import 'package:catalyst_voices/widgets/widgets.dart'; | ||
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
final class LoginEmailTextFiled extends StatelessWidget { | ||
static const emailInputKey = Key('EmailInput'); | ||
|
||
const LoginEmailTextFiled({ | ||
super.key, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BlocBuilder<LoginBloc, LoginState>( | ||
buildWhen: (previous, current) => previous.email != current.email, | ||
builder: (context, state) { | ||
return VoicesEmailTextField( | ||
key: emailInputKey, | ||
onChanged: (email) => _onEmailChanged(context, email), | ||
); | ||
}, | ||
); | ||
} | ||
|
||
void _onEmailChanged(BuildContext context, String email) { | ||
context.read<LoginBloc>().add(LoginEmailChanged(email)); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
catalyst_voices/lib/pages/login/login_password_text_field.dart
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,29 @@ | ||
import 'package:catalyst_voices/widgets/widgets.dart'; | ||
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
final class LoginPasswordTextField extends StatelessWidget { | ||
static const passwordInputKey = Key('PasswordInput'); | ||
|
||
const LoginPasswordTextField({ | ||
super.key, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BlocBuilder<LoginBloc, LoginState>( | ||
buildWhen: (previous, current) => previous.password != current.password, | ||
builder: (context, state) { | ||
return VoicesPasswordTextField( | ||
key: passwordInputKey, | ||
onChanged: (password) => _onPasswordChanged(context, password), | ||
); | ||
}, | ||
); | ||
} | ||
|
||
void _onPasswordChanged(BuildContext context, String password) { | ||
context.read<LoginBloc>().add(LoginPasswordChanged(password)); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...idgets/voices_app_bar/voices_app_bar.dart → ...s/lib/widgets/app_bar/voices_app_bar.dart
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
catalyst_voices/lib/widgets/text_field/voices_email_text_field.dart
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,33 @@ | ||
import 'package:catalyst_voices/widgets/text_field/voices_text_field.dart'; | ||
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
final class VoicesEmailTextField extends StatelessWidget { | ||
/// Emits new value when widget input changes | ||
final ValueChanged<String>? onChanged; | ||
|
||
const VoicesEmailTextField({ | ||
super.key, | ||
this.onChanged, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final l10n = context.l10n; | ||
return VoicesTextField( | ||
keyboardType: TextInputType.emailAddress, | ||
textInputAction: TextInputAction.next, | ||
onChanged: onChanged, | ||
decoration: InputDecoration( | ||
filled: true, | ||
labelText: l10n.emailLabelText, | ||
hintText: l10n.emailHintText, | ||
errorText: l10n.emailErrorText, | ||
border: const OutlineInputBorder(), | ||
), | ||
style: const TextStyle( | ||
fontWeight: FontWeight.w500, | ||
), | ||
); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
catalyst_voices/lib/widgets/text_field/voices_password_text_field.dart
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,35 @@ | ||
import 'package:catalyst_voices/widgets/text_field/voices_text_field.dart'; | ||
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
final class VoicesPasswordTextField extends StatelessWidget { | ||
/// Emits new value when widget input changes | ||
final ValueChanged<String>? onChanged; | ||
|
||
const VoicesPasswordTextField({ | ||
super.key, | ||
this.onChanged, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final l10n = context.l10n; | ||
return VoicesTextField( | ||
keyboardType: TextInputType.multiline, | ||
obscureText: true, | ||
textInputAction: TextInputAction.done, | ||
onChanged: onChanged, | ||
decoration: InputDecoration( | ||
filled: true, | ||
errorMaxLines: 2, | ||
labelText: l10n.passwordLabelText, | ||
hintText: l10n.passwordHintText, | ||
errorText: l10n.passwordErrorText, | ||
border: const OutlineInputBorder(), | ||
), | ||
style: const TextStyle( | ||
fontWeight: FontWeight.w500, | ||
), | ||
); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
catalyst_voices/lib/widgets/text_field/voices_text_field.dart
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,59 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
/// Base Voices TextField widget | ||
class VoicesTextField extends StatelessWidget { | ||
/// [TextField.controller] | ||
final TextEditingController? controller; | ||
|
||
/// [TextField.focusNode] | ||
final FocusNode? focusNode; | ||
|
||
/// [TextField.decoration] | ||
final InputDecoration? decoration; | ||
|
||
/// [TextField.keyboardType] | ||
final TextInputType? keyboardType; | ||
|
||
/// [TextField.textInputAction] | ||
final TextInputAction? textInputAction; | ||
|
||
/// [TextField.textCapitalization] | ||
final TextCapitalization textCapitalization; | ||
|
||
/// [TextField.style] | ||
final TextStyle? style; | ||
|
||
/// [TextField.obscureText] | ||
final bool obscureText; | ||
|
||
/// [TextField.onChanged] | ||
final ValueChanged<String>? onChanged; | ||
|
||
const VoicesTextField({ | ||
super.key, | ||
this.controller, | ||
this.focusNode, | ||
this.decoration = const InputDecoration(), | ||
this.keyboardType, | ||
this.textInputAction, | ||
this.textCapitalization = TextCapitalization.none, | ||
this.style, | ||
this.obscureText = false, | ||
this.onChanged, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return TextField( | ||
controller: controller, | ||
focusNode: focusNode, | ||
decoration: decoration, | ||
keyboardType: keyboardType, | ||
textInputAction: textInputAction, | ||
textCapitalization: textCapitalization, | ||
style: style, | ||
obscureText: obscureText, | ||
onChanged: onChanged, | ||
); | ||
} | ||
} |
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,2 +1,3 @@ | ||
export 'email_input.dart'; | ||
export 'password_input.dart'; | ||
export 'text_field/voices_email_text_field.dart'; | ||
export 'text_field/voices_password_text_field.dart'; | ||
export 'text_field/voices_text_field.dart'; |
6 changes: 3 additions & 3 deletions
6
catalyst_voices/uikit_example/lib/examples/voices_navigation_example.dart
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