LoaderMixin mixin

Mixin that provides loading dialog management functionality.

This mixin adds the ability to show and dismiss loading dialogs to any class that includes it. It provides a simple, consistent way to manage loading states throughout the SDK.

Features

  • Loading Dialog Management: Show and dismiss loading indicators
  • Consistent UI: Uses the SDK's standard loading dialog
  • Easy Integration: Simple mixin that can be added to any class
  • Context Management: Proper context handling for navigation
  • Reusable Logic: Centralized loading dialog logic

Usage Example

class PaymentService with LoaderMixin {
  Future<void> processPayment(BuildContext context) async {
    showLoader(context); // Show loading dialog

    try {
      await _apiService.processPayment();
    } finally {
      dismissDialog(context); // Always hide loading dialog
    }
  }
}

// In a widget
class PaymentWidget extends StatefulWidget {
  @override
  _PaymentWidgetState createState() => _PaymentWidgetState();
}

class _PaymentWidgetState extends State<PaymentWidget> with LoaderMixin {
  Future<void> _handlePayment() async {
    showLoader(context);

    try {
      await paymentService.processPayment();
    } catch (e) {
      // Handle error
    } finally {
      dismissDialog(context);
    }
  }
}

Loading Dialog Features

The loading dialog provided by this mixin includes:

  • Animated Loading: Lottie-based loading animation
  • Consistent Design: Follows SDK design patterns
  • Automatic Logging: Built-in logging for debugging
  • Responsive Layout: Adapts to different screen sizes

Best Practices

When using this mixin:

  • Always use try-finally blocks to ensure dialogs are dismissed
  • Show loading dialogs before starting async operations
  • Dismiss dialogs when operations complete (success or error)
  • Use the same context for showing and dismissing dialogs
  • Consider user experience - don't show very brief loading states

Integration

This mixin is designed to work with:

  • Services: API calls and business logic
  • Widgets: UI components that need loading states
  • Cubits: State management classes
  • Repositories: Data access classes

Context Requirements

The mixin requires a valid BuildContext for:

  • Navigation: Showing dialogs as routes
  • Theme Access: Consistent styling with the app
  • Localization: Proper text and layout direction
  • Accessibility: Screen reader and navigation support
Mixin applications

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

dismissDialog(BuildContext context) → void
Dismisses the currently displayed dialog.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
showLoader(BuildContext context) → void
Shows a loading dialog over the current screen.
toString() String
A string representation of this object.
inherited

Operators

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