RtCommonFunction class

A comprehensive utility class providing common functions used throughout the application.

This singleton class offers a wide range of utility methods including:

  • Gravatar URL generation
  • Date formatting and parsing
  • Snackbar and dialog display (simple and awesome variants)
  • API status code interpretation
  • URL launching
  • Image picking from camera/gallery
  • Distance calculation
  • File handling

The class follows the Singleton pattern to ensure a single instance is used throughout the application lifecycle.

Access the instance via:

RtCommonFunction.instance.methodName()
// or
Utils.commonFunction.methodName()

See also:

  • RtUtils for static access to this and other utility classes

Constructors

RtCommonFunction()
Factory constructor returns the singleton instance
factory

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

doubleToStringHours(double decimalValue) → String
Converts a decimal hour value to a formatted "HH:MM hrs" string.
getGravatarUrl(String email) → String
Generates a Gravatar URL for the given email address.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
showSimpleWarningSnackBar(String message, String title, {Color? backgroundColor = Colors.white}) → void
Displays a simple warning snackbar at the bottom of the screen.
stringDateToFormattedStringDate(String givenDate) → String
Converts an ISO 8601 date string to a formatted date string.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

instance → RtCommonFunction
Public getter for the singleton instance
no setter

Static Methods

calculateDistance(dynamic lat1, dynamic lon1, dynamic lat2, dynamic lon2) → double
Calculates the distance in miles between two geographic coordinates.
fetchApiResponseStatusCode(int statusCode, String apiName, String apiType) → String
Interprets HTTP status codes and returns a descriptive log message.
getBackgroundColor(ContentType contentType, {Color successColor = Colors.green, Color helpColor = Colors.green, Color errorColor = Colors.red, Color warningColor = Colors.orange}) → Color
Determines the background color for AwesomeSnackbar based on content type.
intDayToStringDay(int day) → String
Converts a DateTime weekday integer to its corresponding day name string.
launchURL(String url) → void
Launches a URL in an external application/browser.
pickCameraImage(ImagePicker picker) → Future<String>
Launches the device camera to capture an image.
pickGalleryImage(ImagePicker picker) → Future<String>
Launches the device gallery/photo library to select an image.
roundDecoration() → BoxDecoration
Creates a standard rounded white box decoration.
showFailureSnackBar(String message, {String title = "", Function? onDismiss}) → void
Displays an awesome-styled failure/error snackbar with optional dismiss callback.
showMaterialDialog({Color color = Colors.grey}) → void
Displays a centered circular progress indicator dialog.
showProgressDialogBox({required String text}) → void
Displays a non-dismissible progress dialog with a custom message.
showSuccessfulSnackBar(String message, {String title = "", Function? onDismiss}) → void
Displays an awesome-styled success snackbar with optional dismiss callback.
showWarningSnackBar(String message, {String title = "", Function? onDismiss}) → void
Displays an awesome-styled warning snackbar with optional dismiss callback.
updateProgressDialogBox(double progress) → void
Updates an existing progress dialog with a new progress value.
urlToFile(String imageUrl) → Future<File>
Downloads an image from a URL and saves it to local storage as a File.