mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-11-09 04:58:58 +00:00
Example for Unit Test (#52)
This commit is contained in:
33
unit_testing/lib/helpers.dart
Normal file
33
unit_testing/lib/helpers.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:unit_testing/api/Places.dart';
|
||||
import 'package:unit_testing/model/location.dart';
|
||||
|
||||
class TouristPlaces {
|
||||
static Future<List<Location>> getData() async {
|
||||
// Here we can call a real API.
|
||||
return await PlacesAPI().fetchAllPlaces();
|
||||
}
|
||||
}
|
||||
|
||||
class FormValidator {
|
||||
static String validateEmail(String email) {
|
||||
final pattern = RegExp(
|
||||
r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+");
|
||||
if (email.isEmpty) {
|
||||
return "please enter email";
|
||||
} else if (!pattern.hasMatch(email)) {
|
||||
return "please enter valid email";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static String validatePassword(String password) {
|
||||
if (password.isEmpty) {
|
||||
return "please enter your password";
|
||||
} else if (password.length < 8) {
|
||||
return "minimum lenght of password must be 8 characters";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user