afya_moja_core/src/helpers library

Functions

audioTime(int duration) String
Converts a duration in seconds to a formatted audio time representation.
cccNumberValidator(dynamic val) String?
Validates a user-entered CCC number.
consentStatusFromJson(String? consentString) ConsentStatus
Converts a consent status string to a ConsentStatus enumeration value.
consentStatusToJson(ConsentStatus? consentStatus) String
Converts a ConsentStatus enumeration value to a consent status string for JSON serialization.
contactTypeFromJson(String? contactString) ContactType
Converts a contact type string to a ContactType enumeration value.
contentAudioVideoDuration(int duration) String
contentReadDuration(int duration) String
dayOfWeekFromJson(String? dayOfWeek) DayOfWeek
dismissSnackBar(String text, Color color, BuildContext context) SnackBarAction
Dismiss snackbar
extractErrorCode(Map<String, dynamic>? body) int
Extracts an error code from a JSON response body.
extractNamesInitials({required String name}) String
extractNamesInitials => Extracts name initials from a name
formatDate(String date, {bool showTime = false}) String
Formats a given date/time string into a user-friendly date representation.
formatPhoneNumber({required String countryCode, required String phoneNumber}) String
Formats a phone number by adding the country code and applying specific rules.
genderFromJson(String? genderString) Gender
Converts a JSON gender string to a corresponding Gender enumeration.
genderToJson(Gender? gender) String
Converts a Gender enumeration to a JSON string representation.
genericFetchFunction({required StreamController streamController, required BuildContext context, required String queryString, required Map<String, dynamic> variables, required String logTitle, String? logDescription}) Future<void>
Generic Fetch Function a generic fetch function for fetching all the problems, allergies medications, tests and diagnoses for the current patient in an episode
getDeviceType(BuildContext context) DeviceScreensType
getDeviceType /// Determines the type of device screen based on its width and orientation.
getErrorMessage([String message = '']) String
Retrieves an error message based on an optional custom message.
getGreetingMessage(String? firstName, {int? currentHour}) String
getGreetingMessage gets the current time of day and determines which type of greetings to show to the user
getSentryEnvironment(AppConfig appConfig) String
getTokenExpiryTimestamp(String? expiresIn) DateTime
expiresIn is in seconds
getUserFriendlyMsg(int code) String
Retrieves a user-friendly error message based on an error code.
hasTokenExpired(DateTime expiresAt, DateTime now) bool
Checks if token has expired based on expiry date returns true if token expires in 10 minutes or less otherwise returns false
headsUpNotification(String? title, String? body) → OverlaySupportEntry
Displays a heads-up notification overlay.
humanizeDate({required TextStyle dateTextStyle, required String loadedDate, bool showTime = false, bool showYear = true}) Widget
isNumeric(String? s) bool
isValidPhoneNumber(String phone) bool
isValidPhoneNumber checks if a number is either a Kenyan , American, UK or Belgium phone number
mapDayOfWeek(int weekday) DayOfWeek
newChatMessageTitle(String? username, String? channelName) String
Generates a title for a new chat message notification.
parseError(Map<String, dynamic>? body) String?
Parses an error message from a JSON response body.
processHttpResponse(Response response) ProcessedResponse
Processes an HTTP response and returns a ProcessedResponse object.
removeUnderscores(String sentence) String
removeUnderscores removes underscores from a sentence
roleValueFromJson(String? roleString) RoleValue
Converts a JSON role string to a corresponding RoleValue enumeration.
snackbar({required dynamic content, int durationSeconds = 10, String? label, Function? callback}) SnackBar
snackbar
summarizeDate(String loadedDate) String
Summarizes a given date/time string into a human-readable format.
titleCase(String sentence) String
titleCase returns a title cased sentence
userEmailValidator(dynamic val) String?
This function performs validation on a user-entered email value. It ensures that the email is not empty and follows a general email pattern. The function returns an error message string if the validation fails, otherwise it returns null to indicate a valid email.
userPinValidator(dynamic val) String?
This function performs validation on a user-entered PIN value. It ensures that the PIN is not empty, consists of only digits, and has a minimum length of four. The function returns an error message string if the validation fails, otherwise it returns null to indicate a valid PIN.
validateKenyanNumber(String phone) bool
validateKenyanNumber checks if a number is either has either prefix of '+254111', '+254110', '+254100', '+2540101', '+254102' or '+2547xx'