Add initial project files and configurations for bus_running_record app
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import "../models/trip.dart";
|
||||
|
||||
class TripValidator {
|
||||
static List<String> validate(Trip trip) {
|
||||
final errors = <String>[];
|
||||
|
||||
// Validate time format
|
||||
if (!RegExp(r"^\d{2}:\d{2}$").hasMatch(trip.scheduledTime)) {
|
||||
errors.add("Invalid time format: ${trip.scheduledTime}");
|
||||
}
|
||||
|
||||
// Validate trip number
|
||||
if (trip.tripNumber.isEmpty) {
|
||||
errors.add("Missing trip number");
|
||||
}
|
||||
|
||||
// Validate duty/running numbers
|
||||
if (trip.dutyNumber.isEmpty || trip.runningNumber.isEmpty) {
|
||||
errors.add("Missing duty or running number");
|
||||
}
|
||||
|
||||
// Validate actual departure time if provided
|
||||
if (trip.actualDepartureTime != null &&
|
||||
!RegExp(r"^\d{2}:\d{2}$").hasMatch(trip.actualDepartureTime!)) {
|
||||
errors.add("Invalid actual departure time format: ${trip.actualDepartureTime}");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
static bool isValid(Trip trip) {
|
||||
return validate(trip).isEmpty;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user