Skip to main content

dialog_manager_kit 1.0.1 copy "dialog_manager_kit: ^1.0.1" to clipboard
dialog_manager_kit: ^1.0.1 copied to clipboard

A robust Flutter dialog management system that handles priority-based queuing, smart interruptions, and route awareness to prevent ghost dialogs.

DialogManagerKit #

A sophisticated Flutter dialog management system. DialogManagerKit ensures your app provides a seamless user experience by handling multiple dialog requests with a priority-based queue, smart preemption (interruptions), and route awareness.

Features #

  • Priority-Based Queuing: Organize dialogs by Low, Medium, or High priority.
  • Smart Preemption: High-priority dialogs automatically dismiss lower-priority ones.
  • Route Awareness: Prevents dialogs from appearing on unintended routes.
  • Transition Buffering: Built-in 300ms delay between dialogs for smooth UI transitions.

Installation #

Add dialog_manager_kit to your pubspec.yaml:

dependencies:
  dialog_manager_kit: ^1.0.0a

Setup #

To enable Route Awareness (ensuring dialogs don't follow users to different pages), add the DialogRouteObserver to your MaterialApp:

import 'package:dialog_manager_kit/dialog_manager_kit.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // CRITICAL: Add this observer to track navigation
      navigatorObservers: [DialogRouteObserver()],
      home: const HomeScreen(),
    );
  }
}

Usage #

  1. Basic Dialog Request Use the DialogQueueManager singleton to add a dialog to the queue.
final manager = DialogQueueManager();

manager.addDialog(
  context,
  DialogRequest(
    priority: DialogPriority.medium,
    showFunc: (ctx) async {
      return showDialog(
        context: ctx,
        builder: (_) => const AlertDialog(
          title: Text('Information'),
          content: Text('This dialog is managed by the queue.'),
        ),
      );
    },
  ),
);
  1. High Priority Interruption If a High priority dialog is requested while a Low or Medium dialog is currently visible, the manager will automatically pop the current dialog and present the urgent one immediately.
manager.addDialog(
  context,
  DialogRequest(
    priority: DialogPriority.high, // Interrupts lower priority dialogs
    showFunc: (ctx) async {
      return showDialog(
        context: ctx,
        builder: (_) => const AlertDialog(
          title: Text('Urgent Alert!'),
          content: Text('This high-priority message interrupted the previous one.'),
        ),
      );
    },
  ),
);

How It Works #

  • Queueing: Every addDialog call adds a request to a list, which is automatically sorted by priority (High > Medium > Low).

  • Preemption: The manager checks if the new request's priority is higher than the currently displayed dialog. If so, it triggers an immediate Navigator.pop().

  • Validation: Before executing showFunc, the manager verifies that the user is still on the same route where the request originated.

  • Synchronization: The manager waits for the showFunc to be dismissed before processing the next item.

  • Transition Delay: A mandatory 300ms buffer is applied between dialogs to ensure the UI remains stable and visually pleasing.

Authors #

Ali Agus Hutapea - Initial Work - aliagus

License #

This project is licensed under the MIT License - see the LICENSE file for details.

1
likes
140
points
52
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A robust Flutter dialog management system that handles priority-based queuing, smart interruptions, and route awareness to prevent ghost dialogs.

Repository (GitLab)

License

MIT (license)

Dependencies

flutter, meta

More

Packages that depend on dialog_manager_kit