custom_error 0.0.6 copy "custom_error: ^0.0.6" to clipboard
custom_error: ^0.0.6 copied to clipboard

The "custom_error" library is a powerful flutter package designed to streamline error management and elevate error handling in your flutter applications.

0.0.6 #

Added #

  • getLatestError() retrieves the last error added
  • findErrorByCode(int errorcode) retrieves all errors matching the given code

0.0.5 #

Added #

  • Added Error Reporting (send to server or email)
  • Added Message Logging
  • Added Colored Console Messages

Changed #

  • Improved error handling and error instance access.

Key Features #

  • Custom Error Management: Create and manage custom error objects with error codes and messages.
  • Flexible Error Storage: Store multiple errors using a list of maps.
  • Error Retrieval: Easily access individual error details using getter methods.
  • Error State Check: Check if an error exists with the hasAnError() method.
  • Type Checking: Determine if an object is an instance of CustomError using the isAnError() method.
  • Show dialogs with custom titles, messages, and actions when an error occurs.
  • Display SnackBars with custom backgrounds and behaviors based on error conditions.
  • Error Logging report errors to a remote server / email / log for further analysis. This can help in identifying and fixing issues in production.
  • Colored Console Messages display different color messages based on the error level

Usage Example #

Here are some examples of how to use the Custom Error Reporting library in your Dart application:

// Log an error message
CustomErrorManager().log(e: 'This is an error message');

// Show a dialog if an error exists
CustomError customError = CustomError();
CustomErrorManager.showDialogIfError(context, customError, 'Error', 'An error occurred', null);

// Show a SnackBar if an error exists
CustomErrorManager.showSnackBarIfError(context, customError, backgroundColor: Colors.red);

// Send an error report to a server
CustomErrorManager().sendToServer(url: 'https://example.com/report', methodType: 'POST', body: 'Report data');

// Email a log message
CustomErrorManager().emailLog(message: 'Error message', recipient: 'recipient@example.com', appTitle: 'My App');

0.0.4 #

Added #

  • Added Dart doc documentation
  • Added CustomErrorManager

Changed #

  • Improved error handling and error instance access.

Key Features #

  • Custom Error Management: Create and manage custom error objects with error codes and messages.
  • Flexible Error Storage: Store multiple errors using a list of maps.
  • Error Retrieval: Easily access individual error details using getter methods.
  • Error State Check: Check if an error exists with the hasAnError() method.
  • Type Checking: Determine if an object is an instance of CustomError using the isAnError() method.
  • Show dialogs with custom titles, messages, and actions when an error occurs.
  • Display SnackBars with custom backgrounds and behaviors based on error conditions.

Usage Example #

import 'package:custom_error/custom_error.dart';

void main() {
  String _inputText = 'Mazzi';
  List<String> names = ['Yung', 'Cet', 'Cedric'];

  // Create and manage custom errors
  CustomError error = CustomError();
  if (! names.contains(_inputText)){
    error.setError(-1, 'Name not found.');
  }

  // Check if an error exists
  // you can also use error.isAnError(), instead of error.hasAnError()
  // To display a dialog / snackbar when an error has occured use CustomErrorManager, see examples below
  if (error.hasAnError()) {
    // handle error
    print('Error: ${error.getError()}, Code: ${error.getErrorCode()}');
  } else {
    print('No error found.');
  }

  // Add multiple errors
  error.addError(200, 'Error 200');
  error.addError(300, 'Error 300');

  // Retrieve all errors
  final allErrors = error.getAllErrors();

  // Check if an error exists
  if (error.isAnError()) {
    print('All Errors: $allErrors');
  } else {
    print('No error found.');
  }
}

Showing a Dialog / SnackBar when an error occurs using CustomErrorManager #

Error Dialog

import 'package:custom_error/custom_error.dart';
import 'package:custom_error/custom_error_manager.dart';

...
...
  ElevatedButton(
    onPressed: (){
      CustomError customError = CustomError();
      customError.setError(-1, 'Showing Error Dialog');

      // add dialog buttons
      final actions = <Widget>[
        TextButton(
          onPressed: () {
            Navigator.of(context).pop();
            // add code logic for the button
          },
          child: Text('OK'),
        ),
        TextButton(
          onPressed: () {
            Navigator.of(context).pop();
            // add code logic for the button
          },
          child: Text('Cancel'),
        )
      ];

      // Show a dialog when an error occurs
      CustomErrorManager.showDialogIfError(
        context,
        customError,
        "Error Title",
        "Optional error message", // if set to null, customError.getError() message will be used
        actions,
      );
    },
    child: Text('Show Error Dialog'),
  ),
  ...
  ...

Error SnackBar

import 'package:custom_error/custom_error.dart';
import 'package:custom_error/custom_error_manager.dart';

...
...
  ElevatedButton(
    onPressed: (){
      CustomError customError = CustomError();
      customError.setError(-1, 'Showing Error SnackBar');

      // Display a SnackBar when an error occurs
      CustomErrorManager.showSnackBarIfError(
        context,
        customError,
        backgroundColor: Colors.red,
        behavior: SnackBarBehavior.floating,
      );
    },
    child: Text('Show Error SnackBar'),
  )
  ...
  ...

0.0.3 #

Added #

  • The CustomError constructor no longer needs parameters.
  • A new function hasAnError() to check if an error exists.

Changed #

  • Improved error handling and error instance access.

Key Features #

  • Custom Error Management: Create and manage custom error objects with error codes and messages.
  • Flexible Error Storage: Store multiple errors using a list of maps.
  • Error Retrieval: Easily access individual error details using getter methods.
  • Error State Check: Check if an error exists with the hasAnError() method.
  • Type Checking: Determine if an object is an instance of CustomError using the isAnError() method.

Usage Example #

import 'package:custom_error/custom_error.dart';

void main() {
  String _inputText = 'Mazzi';
  List<String> names = ['Yung', 'Cet', 'Cedric'];

  // Create and manage custom errors
  CustomError error = CustomError();
  if (! names.contains(_inputText)){
    error.setError(-1, 'Name not found.');
  }

  // Check if an error exists
  // you can also use error.isAnError(), instead of error.hasAnError()
  if (error.hasAnError()) {
    // handle error
    print('Error: ${error.getError()}, Code: ${error.getErrorCode()}');
  } else {
    print('No error found.');
  }

  // Add multiple errors
  error.addError(200, 'Error 200');
  error.addError(300, 'Error 300');

  // Retrieve all errors
  final allErrors = error.getAllErrors();

  // Check if an error exists
  if (error.isAnError()) {
    print('All Errors: $allErrors');
  } else {
    print('No error found.');
  }
}

0.0.2 #

Added #

  • Changed Error class to CustomError.

Changed #

  • Improved error handling and error instance access.

Key Features #

  • Custom Error Management: Create and manage custom error objects with error codes and messages.
  • Flexible Error Storage: Store multiple errors using a list of maps.
  • Error Retrieval: Easily access individual error details using getter methods.
  • Comprehensive Error Access: Retrieve all errors for debugging and reporting.
  • Type Checking: Verify if a value is an instance of the Error class.

Usage Example #

import 'package:custom_error/custom_error.dart';

void main() {
  // Create and manage custom errors
  final error = CustomError(100, 'Error 100');
  // Check if a value is an Error instance
  bool isCustomError = error.isAnError(error);

  // Access error details
  String errorMessage = error.getError();
  int errorCode = error.getErrorCode();

  // add multiple errors
  error.addError(200, 'Error 200');

  // Retrieve all errors
  List<Map<String, dynamic>> allErrors = error.getAllErrors();

}

0.0.1 #

Initial Release Changelog #

We are excited to announce the initial release of the "custom_error" package. This release marks the beginning of a new era in error management for Dart developers. "custom_error" empowers you to create, store, and access custom error instances with ease, making error handling more efficient and effective in your Dart applications.

Key Features #

  • Custom Error Management: Create and manage custom error objects with error codes and messages.
  • Flexible Error Storage: Store multiple errors using a list of maps.
  • Error Retrieval: Easily access individual error details using getter methods.
  • Comprehensive Error Access: Retrieve all errors for debugging and reporting.
  • Type Checking: Verify if a value is an instance of the Error class.

Usage Example #

import 'package:custom_error/custom_error.dart';
void main() {
  // Create and manage custom errors
  final error = Error(100, 'Error 100');
  error.AddError(200, 'Error 200');
  // Access error details
  String errorMessage = error.getError();
  int errorCode = error.getErrorCode();
  // Retrieve all errors
  List<Map<String, dynamic>> allErrors = error.getAllErrors();
  // Check if a value is an Error instance
  bool isCustomError = error.isAnError(error);
}
5
likes
140
points
47
downloads

Publisher

verified publisherpermanentlink.co.za

Weekly Downloads

The "custom_error" library is a powerful flutter package designed to streamline error management and elevate error handling in your flutter applications.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http, intl, ndialog

More

Packages that depend on custom_error