Last active
May 26, 2024 08:04
-
-
Save ethaizone/e41b3ff13564c92bdf28ca43b53b3b22 to your computer and use it in GitHub Desktop.
Revisions
-
ethaizone revised this gist
May 26, 2024 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ enum ValidationError { empty } // Magical happen in here but it's on this enum only. Not in prototype. extension ValidationErrorMessage on ValidationError { String text(String label) { switch (this) { case ValidationError.empty: @@ -21,4 +21,7 @@ ValidationError? validate(value) { // Validate then return error message var errorMessage = validate(null)?.text(); print('Error message: $errorMessage'); // FYI. If someone found issue as method doesn't exists on other library. // Run `flutter clean`, reopen IDE and run `flutter pub get` again. -
ethaizone revised this gist
May 20, 2024 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,12 +13,12 @@ extension on ValidationError { } // Example validate function ValidationError? validate(value) { if (value == null) return ValidationError.empty; return null; } // Validate then return error message var errorMessage = validate(null)?.text(); print('Error message: $errorMessage'); -
ethaizone created this gist
May 20, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ // Example about using extension on Enum. enum ValidationError { empty } // Magical happen in here but it's on this enum only. Not in prototype. extension on ValidationError { String text(String label) { switch (this) { case ValidationError.empty: return 'Please enter a password'; } } } // Example validate function ValidationError validate(value) { if (value == null) return ValidationError.empty; return null; } // Validate then return error message var errorMessage = validate(null)?.text() print('Error message: $errorMessage');