From 4ff212ad9146d851278b9dae4f83cd70378838ce Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Fri, 4 Nov 2022 11:38:16 +0100 Subject: [PATCH] fix: translate defaultsteps and emailregex fix --- example/lib/main.dart | 2 +- example/pubspec.lock | 2 +- lib/src/config/registration_options.dart | 20 +++++---- lib/src/config/registration_translations.dart | 14 ++++++ pubspec.yaml | 45 +++---------------- 5 files changed, 33 insertions(+), 50 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index c1b1d5a..b5d639a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -22,7 +22,7 @@ class FlutterRegistrationDemo extends StatelessWidget { return RegistrationScreen( registrationOptions: RegistrationOptions( registrationRepository: ExampleRegistrationRepository(), - registrationSteps: RegistrationOptions.defaultSteps, + registrationSteps: RegistrationOptions.getDefaultSteps(), afterRegistration: () { debugPrint('Registered!'); }, diff --git a/example/pubspec.lock b/example/pubspec.lock index 776cf0f..a0a564a 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -80,7 +80,7 @@ packages: path: ".." relative: true source: path - version: "0.0.1" + version: "0.1.0" flutter_test: dependency: "direct dev" description: flutter diff --git a/lib/src/config/registration_options.dart b/lib/src/config/registration_options.dart index 35403fb..a03aeb4 100644 --- a/lib/src/config/registration_options.dart +++ b/lib/src/config/registration_options.dart @@ -20,22 +20,25 @@ class RegistrationOptions { final RegistrationRepository registrationRepository; final AppBar Function(String title)? customAppbarBuilder; - static List get defaultSteps => [ + static List getDefaultSteps({ + RegistrationTranslations translations = const RegistrationTranslations(), + }) => + [ AuthStep( fields: [ AuthTextField( name: 'email', - title: 'Wat is je e-mailadres?', - hintText: 'iemand@voorbeeld.nl', + title: translations.defaultEmailTitle, + hintText: translations.defaultEmailHint, validators: [ (email) => (email == null || email.isEmpty) - ? 'Geef uw e-mailadres op' + ? translations.defaultEmailEmpty : null, (email) => - RegExp(r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+") + RegExp(r"""(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])""") .hasMatch(email!) ? null - : 'Geef een geldig e-mailadres op', + : translations.defaultEmailValidatorMessage, ], ) ], @@ -44,11 +47,12 @@ class RegistrationOptions { fields: [ AuthTextField( name: 'password', - title: 'Kies een wachtwoord', + title: translations.defaultPasswordTitle, + hintText: translations.defaultPasswordHint, obscureText: true, validators: [ (value) => (value == null || value.isEmpty) - ? 'Geef een wachtwoord op' + ? translations.defaultPasswordValidatorMessage : null, ], ), diff --git a/lib/src/config/registration_translations.dart b/lib/src/config/registration_translations.dart index 7613c9c..55a7dbe 100644 --- a/lib/src/config/registration_translations.dart +++ b/lib/src/config/registration_translations.dart @@ -9,6 +9,13 @@ class RegistrationTranslations { this.previousStepBtn = 'Vorige stap', this.nextStepBtn = 'Volgende stap', this.closeBtn = 'Sluiten', + this.defaultEmailTitle = 'Wat is je e-mailadres?', + this.defaultEmailHint = 'iemand@voorbeeld.nl', + this.defaultEmailEmpty = 'Geef uw e-mailadres op', + this.defaultEmailValidatorMessage = 'Geef een geldig e-mailadres op', + this.defaultPasswordTitle = 'Kies een wachtwoord', + this.defaultPasswordHint = '', + this.defaultPasswordValidatorMessage = 'Geef een wachtwoord op', }); final String title; @@ -16,4 +23,11 @@ class RegistrationTranslations { final String previousStepBtn; final String nextStepBtn; final String closeBtn; + final String defaultEmailTitle; + final String defaultEmailHint; + final String defaultEmailEmpty; + final String defaultEmailValidatorMessage; + final String defaultPasswordTitle; + final String defaultPasswordHint; + final String defaultPasswordValidatorMessage; } diff --git a/pubspec.yaml b/pubspec.yaml index aa454df..9dbedfd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,9 +3,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later name: flutter_registration -description: A standard flutter package. -version: 0.0.1 -homepage: +description: A Flutter Registration package +version: 0.1.0 +repository: https://github.com/Iconica-Development/flutter_registration environment: sdk: '>=2.18.0 <3.0.0' @@ -16,46 +16,11 @@ dependencies: sdk: flutter flutter_localizations: sdk: flutter - flutter_hooks: ^0.18.5+1 + flutter_hooks: any dev_dependencies: flutter_test: sdk: flutter 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: - - # 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 +flutter: \ No newline at end of file