feat: expanded translations

This commit is contained in:
Freek van de Ven 2022-11-04 09:23:48 +01:00
parent 098feec337
commit bc39a1ebfa
8 changed files with 28 additions and 42 deletions

2
.gitignore vendored
View file

@ -19,7 +19,7 @@ migrate_working_dir/
# The .vscode folder contains launch configuration and tasks you configure in # The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line # VS Code which you may wish to be included in version control, so this line
# is commented out by default. # is commented out by default.
#.vscode/ .vscode/
# Flutter/Dart/Pub related # Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.

View file

@ -1,3 +1,6 @@
## 2.0.2
* Added more translatable options
## 2.0.1 ## 2.0.1
* Fixed email regex * Fixed email regex

View file

@ -16,6 +16,7 @@ final loginOptions = LoginOptions(
onPressed, onPressed,
isDisabled, isDisabled,
onDisabledPress, onDisabledPress,
translations,
) { ) {
return Opacity( return Opacity(
opacity: isDisabled ? 0.5 : 1.0, opacity: isDisabled ? 0.5 : 1.0,

View file

@ -61,7 +61,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "2.0.1" version: "2.0.2"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter

View file

@ -60,11 +60,19 @@ class LoginTranslations {
this.emailEmpty = 'Email is required', this.emailEmpty = 'Email is required',
this.passwordEmpty = 'Password is required', this.passwordEmpty = 'Password is required',
this.emailInvalid = 'Enter a valid email address', this.emailInvalid = 'Enter a valid email address',
this.loginButton = 'Login',
this.forgotPasswordButton = 'Forgot password?',
this.requestForgotPasswordButton = 'Send request',
this.registrationButton = 'Create Account',
}); });
final String emailInvalid; final String emailInvalid;
final String emailEmpty; final String emailEmpty;
final String passwordEmpty; final String passwordEmpty;
final String loginButton;
final String forgotPasswordButton;
final String requestForgotPasswordButton;
final String registrationButton;
} }
Widget _createEmailInputContainer(Widget child) => child; Widget _createEmailInputContainer(Widget child) => child;
@ -76,12 +84,13 @@ Widget _createLoginButton(
OptionalAsyncCallback onPressed, OptionalAsyncCallback onPressed,
bool disabled, bool disabled,
OptionalAsyncCallback onDisabledPress, OptionalAsyncCallback onDisabledPress,
LoginTranslations translations,
) { ) {
return Opacity( return Opacity(
opacity: disabled ? 0.5 : 1.0, opacity: disabled ? 0.5 : 1.0,
child: ElevatedButton( child: ElevatedButton(
onPressed: !disabled ? onPressed : onDisabledPress, onPressed: !disabled ? onPressed : onDisabledPress,
child: const Text('Login'), child: Text(translations.loginButton),
), ),
); );
} }
@ -91,12 +100,13 @@ Widget _createForgotPasswordButton(
OptionalAsyncCallback onPressed, OptionalAsyncCallback onPressed,
bool disabled, bool disabled,
OptionalAsyncCallback onDisabledPress, OptionalAsyncCallback onDisabledPress,
LoginTranslations translations,
) { ) {
return Opacity( return Opacity(
opacity: disabled ? 0.5 : 1.0, opacity: disabled ? 0.5 : 1.0,
child: ElevatedButton( child: ElevatedButton(
onPressed: !disabled ? onPressed : onDisabledPress, onPressed: !disabled ? onPressed : onDisabledPress,
child: const Text('Forgot password?'), child: Text(translations.forgotPasswordButton),
), ),
); );
} }
@ -106,12 +116,13 @@ Widget _createRequestForgotPasswordButton(
OptionalAsyncCallback onPressed, OptionalAsyncCallback onPressed,
bool disabled, bool disabled,
OptionalAsyncCallback onDisabledPress, OptionalAsyncCallback onDisabledPress,
LoginTranslations translations,
) { ) {
return Opacity( return Opacity(
opacity: disabled ? 0.5 : 1.0, opacity: disabled ? 0.5 : 1.0,
child: ElevatedButton( child: ElevatedButton(
onPressed: !disabled ? onPressed : onDisabledPress, onPressed: !disabled ? onPressed : onDisabledPress,
child: const Text('Send request'), child: Text(translations.requestForgotPasswordButton),
), ),
); );
} }
@ -121,12 +132,13 @@ Widget _createRegisterButton(
OptionalAsyncCallback onPressed, OptionalAsyncCallback onPressed,
bool disabled, bool disabled,
OptionalAsyncCallback onDisabledPress, OptionalAsyncCallback onDisabledPress,
LoginTranslations translations,
) { ) {
return Opacity( return Opacity(
opacity: disabled ? 0.5 : 1.0, opacity: disabled ? 0.5 : 1.0,
child: ElevatedButton( child: ElevatedButton(
onPressed: !disabled ? onPressed : onDisabledPress, onPressed: !disabled ? onPressed : onDisabledPress,
child: const Text('Create Account'), child: Text(translations.registrationButton),
), ),
); );
} }
@ -136,6 +148,7 @@ typedef ButtonBuilder = Widget Function(
OptionalAsyncCallback onPressed, OptionalAsyncCallback onPressed,
bool isDisabled, bool isDisabled,
OptionalAsyncCallback onDisabledPress, OptionalAsyncCallback onDisabledPress,
LoginTranslations options,
); );
typedef InputContainerBuilder = Widget Function( typedef InputContainerBuilder = Widget Function(

View file

@ -162,6 +162,7 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
}, },
false, false,
() {}, () {},
options.translations,
), ),
), ),
], ],
@ -176,6 +177,7 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
() { () {
_formKey.currentState?.validate(); _formKey.currentState?.validate();
}, },
options.translations,
); );
}, },
), ),
@ -190,6 +192,7 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
}, },
false, false,
() {}, () {},
options.translations,
), ),
] ]
], ],

View file

@ -133,6 +133,7 @@ class _ForgotPasswordFormState extends State<ForgotPasswordForm> {
() { () {
_formKey.currentState?.validate(); _formKey.currentState?.validate();
}, },
options.translations,
), ),
); );
}, },

View file

@ -1,6 +1,6 @@
name: flutter_login name: flutter_login
description: A new Flutter package project. description: A new Flutter package project.
version: 2.0.1 version: 2.0.2
environment: environment:
sdk: ">=2.18.1 <3.0.0" sdk: ">=2.18.1 <3.0.0"
@ -15,39 +15,4 @@ dev_dependencies:
sdk: flutter sdk: flutter
flutter_lints: ^2.0.0 flutter_lints: ^2.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter: flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/custom-fonts/#from-packages