adaptive_dialog_manager 1.0.1
adaptive_dialog_manager: ^1.0.1 copied to clipboard
A comprehensive Flutter adaptive dialog manager package that provides multi-platform dialog support with responsive design, accessibility features, and platform-specific behaviors.
Adaptive Dialog Manager #
A comprehensive Flutter package that provides adaptive, responsive dialog management across all platforms including mobile, web, desktop, and tablet with platform-specific behaviors, accessibility support, and advanced notification systems.
Features #
🎯 Adaptive & Responsive #
- Multi-platform support: Android, iOS, Web, Windows, macOS, Linux, Fuchsia
- Responsive design: Automatic layout adaptation for mobile, tablet, and desktop
- Platform-specific behaviors: Material, Cupertino, Fluent, and macOS design systems
- Breakpoint-aware: Smart sizing based on screen dimensions
- Queue management: Handle multiple dialogs, snackbars, and toasts gracefully with intelligent queuing
🎨 Dialog System #
- 25+ dialog types: Alert, confirmation, input, loading, progress, bottomSheet, custom, modal, fullScreen, datePicker, timePicker, colorPicker, filePicker, search, settings, about, help, error, warning, success, info, toast, snackbar
- Platform-specific styling: Automatic adaptation to Material, Cupertino, Fluent, and macOS design languages
- Custom content support: Fully customizable dialog content with widget injection
- Advanced configurations: Comprehensive dialog configuration with safe type handling
🍞 Toast System #
- 5 toast types: Info, success, warning, error, custom
- Flexible positioning: Top, bottom, center positioning with offset control
- Stack and column layouts: Traditional overlapping or vertical column display
- Column mode features: Maximum 4 visible toasts, clean vertical arrangement
- Timing management: Automatic duration control with pause/resume capabilities
- Custom content: Widget-based custom toast content
📱 Snackbar System #
- 10 snackbar types: Info, success, warning, error, loading, action, custom, toast, banner, persistent
- Advanced positioning: Top, bottom, center with fine-grained control
- Behavior types: Fixed, floating, pinned behaviors
- Action support: Interactive buttons with customizable callbacks
- Priority queue: Intelligent priority-based queue management
🎭 Animations & Transitions #
- 16 built-in animation types: None, fade, scale, slideFromBottom, slideFromTop, slideFromLeft, slideFromRight, slideUp, slideDown, elastic, bounce, rotation, flip, pop, blur, custom
- Platform-optimized timing: Adaptive durations and curves
- Performance profiles: Mobile-friendly and high-performance variants
- Reduced motion support: Accessibility-friendly alternatives
♿ Accessibility #
- Screen reader support: Comprehensive semantic labeling
- Keyboard navigation: Full desktop keyboard support
- Focus management: Proper focus trapping and restoration
- High contrast support: Theme-aware color schemes
- Touch target sizing: Minimum accessibility requirements
🔧 Developer Experience #
- Type-safe configuration: Strongly typed models extending BaseDataModel
- Dependency injection ready: Abstract interfaces for testability
- State tracking: Comprehensive lifecycle monitoring with streams
- Error handling: Robust exception management with detailed error reporting
- Debug mode: Detailed logging for development
- Queue monitoring: Real-time queue status and management
Installation #
Add to your pubspec.yaml
:
dependencies:
adaptive_dialog_manager: ^1.0.0
flutter_shared_utilities: ^1.0.6
Run:
flutter pub get
Platform Setup #
Android
No additional setup required.
iOS
No additional setup required.
Web
No additional setup required.
Windows
No additional setup required.
macOS
No additional setup required.
Linux
No additional setup required.
Quick Start #
Basic Setup #
import 'package:adaptive_dialog_manager/adaptive_dialog_manager.dart';
void main() {
// Initialize the managers
AdaptiveDialogManager.initialize();
AdaptiveSnackbarManager.initialize();
AdaptiveToastManager.initialize();
runApp(MyApp());
}
Dialog Examples #
Simple Alert Dialog
final dialogManager = AdaptiveDialogManager.instance;
await dialogManager.showDialog(
context,
DialogConfig(
dialogType: DialogType.alert,
platformType: PlatformDetector.currentPlatform,
title: 'Hello World',
content: 'This is an adaptive dialog!',
),
);
Confirmation Dialog
final result = await dialogManager.showDialog<bool>(
context,
DialogConfig(
dialogType: DialogType.confirmation,
platformType: PlatformDetector.currentPlatform,
title: 'Delete Item',
content: 'Are you sure you want to delete this item?',
actions: [
DialogAction(
label: 'Cancel',
onPressed: () => Navigator.pop(context, false),
),
DialogAction(
label: 'Delete',
isPrimary: true,
isDestructive: true,
onPressed: () => Navigator.pop(context, true),
),
],
),
);
if (result?.data == true) {
// Handle deletion
}
Custom Dialog with Animations
final config = DialogConfig(
dialogType: DialogType.custom,
platformType: PlatformDetector.currentPlatform,
animationType: AnimationType.elastic,
animationDuration: const Duration(milliseconds: 600),
customContent: MyCustomWidget(),
backgroundColor: Colors.white,
borderRadius: BorderRadius.circular(16),
);
await dialogManager.showDialog(context, config);
Snackbar Examples #
Basic Snackbars
final snackbarManager = AdaptiveSnackbarManager.instance;
// Success snackbar
await snackbarManager.showSnackbar(
context,
SnackbarConfig(
snackbarType: SnackbarType.success,
platformType: PlatformDetector.currentPlatform,
message: 'Operation completed successfully!',
),
);
// Error snackbar with action
await snackbarManager.showSnackbar(
context,
SnackbarConfig(
snackbarType: SnackbarType.error,
platformType: PlatformDetector.currentPlatform,
message: 'Failed to save data',
action: SnackbarAction(
label: 'Retry',
onPressed: () => retryOperation(),
),
),
);
Advanced Snackbar Configuration
final config = SnackbarConfig(
snackbarType: SnackbarType.custom,
platformType: PlatformDetector.currentPlatform,
message: 'Custom snackbar',
position: SnackbarPosition.top,
behavior: SnackbarBehavior.floating,
duration: const Duration(seconds: 5),
backgroundColor: Colors.purple,
textColor: Colors.white,
borderRadius: BorderRadius.circular(12),
customContent: MyCustomSnackbarContent(),
);
await snackbarManager.showSnackbar(context, config);
Toast Examples #
Basic Toast Notifications
final toastManager = AdaptiveToastManager.instance;
// Info toast
await toastManager.showInfo(
context,
message: 'This is an info message',
title: 'Information',
);
// Success toast
await toastManager.showSuccess(
context,
message: 'Data saved successfully!',
duration: const Duration(seconds: 3),
);
// Error toast
await toastManager.showError(
context,
message: 'Failed to load data',
title: 'Error',
);
Custom Toast
await toastManager.showCustom(
context,
content: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(8),
),
child: const Text(
'Custom Toast Content',
style: TextStyle(color: Colors.white),
),
),
duration: const Duration(seconds: 4),
);
Column Layout Toast
// Show toast in column layout mode
await toastManager.showToast<String>(
context,
ToastConfig(
toastType: ToastType.info,
platformType: PlatformDetector.currentPlatform,
message: 'Column layout toast',
title: 'Information',
position: ToastPosition.bottomCenter,
layout: ToastLayout.column, // Use column layout
duration: const Duration(seconds: 4),
),
);
// Multiple toasts in column - max 4 visible at once
for (int i = 1; i <= 6; i++) {
await toastManager.showToast<String>(
context,
ToastConfig(
toastType: ToastType.success,
platformType: PlatformDetector.currentPlatform,
message: 'Toast #$i',
layout: ToastLayout.column,
position: ToastPosition.topCenter,
),
);
}
// Only 4 toasts will be visible at once in column mode
Advanced Usage #
Platform Detection & Responsive Design #
// Get current platform
final platformType = PlatformDetector.currentPlatform;
// Get responsive breakpoint
final breakpoint = ResponsiveBreakpoint.fromWidth(
MediaQuery.of(context).size.width,
);
// Create responsive configuration
final responsiveConfig = ResponsiveConfig(
breakpoint: breakpoint,
maxWidth: breakpoint.isDesktop ? 600 : double.infinity,
padding: breakpoint.isMobile
? const EdgeInsets.all(16)
: const EdgeInsets.all(24),
);
Queue Management #
// Get queue status
final dialogQueue = DialogQueueManager.instance;
final snackbarQueue = SnackbarQueueManager.instance;
final toastQueue = ToastQueueManager.instance;
// Monitor queue changes
dialogQueue.stateStream.listen((dialogState) {
print('Dialog state: ${dialogState.status}');
});
// Clear queues
await dialogQueue.clearQueue();
await snackbarQueue.clearQueue();
await toastQueue.clearQueue();
Debug Mode #
// Enable debug logging
AdaptiveDialogManager.instance.enableDebugMode();
AdaptiveSnackbarManager.instance.enableDebugMode();
AdaptiveToastManager.instance.enableDebugMode();
// View queue status
final dialogStatus = DialogQueueManager.instance.getQueueStatus();
print('Active dialogs: ${dialogStatus.activeCount}');
print('Pending dialogs: ${dialogStatus.pendingCount}');
Architecture #
Core Classes #
AdaptiveDialogManager
- Main dialog manager singletonAdaptiveSnackbarManager
- Snackbar manager singletonAdaptiveToastManager
- Toast manager singletonDialogConfig
- Dialog configuration modelSnackbarConfig
- Snackbar configuration modelToastConfig
- Toast configuration modelDialogResult<T>
- Type-safe dialog resultSnackbarResult<T>
- Type-safe snackbar resultToastResult<T>
- Type-safe toast resultPlatformDetector
- Platform detection utilityResponsiveManager
- Responsive layout manager
Enums #
DialogType
- 25+ dialog typesSnackbarType
- 10 snackbar typesToastType
- 5 toast typesPlatformType
- 7 supported platformsAnimationType
- 16 animation optionsResponsiveBreakpoint
- Screen size breakpointsSnackbarPosition
,SnackbarBehavior
- Advanced snackbar optionsToastPosition
,ToastLayout
- Toast positioning and layout options
Interfaces #
abstract class DialogManager {
Future<DialogResult<T?>?> showDialog<T>(BuildContext context, DialogConfig config);
Stream<DialogState> get stateStream;
void enableDebugMode();
void disableDebugMode();
}
abstract class SnackbarManager {
Future<SnackbarResult<T?>?> showSnackbar<T>(BuildContext context, SnackbarConfig config);
Stream<SnackbarState> get stateStream;
}
abstract class ToastManager {
Future<ToastResult<T>?> showToast<T>(BuildContext context, ToastConfig config);
Future<ToastResult<String>?> showInfo(BuildContext context, {required String message});
Future<ToastResult<String>?> showSuccess(BuildContext context, {required String message});
Future<ToastResult<String>?> showWarning(BuildContext context, {required String message});
Future<ToastResult<String>?> showError(BuildContext context, {required String message});
}
Testing #
Unit Testing #
import 'package:flutter_test/flutter_test.dart';
import 'package:adaptive_dialog_manager/adaptive_dialog_manager.dart';
void main() {
group('DialogConfig', () {
test('should create valid configuration', () {
final config = DialogConfig(
dialogType: DialogType.alert,
platformType: PlatformType.android,
title: 'Test',
content: 'Test content',
);
expect(config.dialogType, DialogType.alert);
expect(config.title, 'Test');
expect(config.content, 'Test content');
});
});
group('PlatformDetector', () {
test('should detect current platform', () {
final platform = PlatformDetector.currentPlatform;
expect(platform, isA<PlatformType>());
});
});
}
Widget Testing #
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:adaptive_dialog_manager/adaptive_dialog_manager.dart';
void main() {
setUp(() {
AdaptiveDialogManager.initialize();
});
testWidgets('should show adaptive dialog', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (context) => ElevatedButton(
onPressed: () async {
await AdaptiveDialogManager.instance.showDialog(
context,
DialogConfig(
dialogType: DialogType.alert,
platformType: PlatformDetector.currentPlatform,
title: 'Test Dialog',
content: 'Test content',
),
);
},
child: const Text('Show Dialog'),
),
),
),
);
await tester.tap(find.text('Show Dialog'));
await tester.pumpAndSettle();
expect(find.text('Test Dialog'), findsOneWidget);
expect(find.text('Test content'), findsOneWidget);
});
}
Performance #
Optimization Features #
- Lazy initialization: Managers initialize only when needed
- Efficient queue management: Optimized algorithms for multiple notifications
- Memory management: Automatic cleanup and disposal
- Animation optimization: Mobile-friendly and high-performance variants
- Platform-specific optimizations: Tailored behavior for each platform
Performance Profiles #
// Mobile-optimized configuration
final mobileConfig = DialogConfig(
dialogType: DialogType.alert,
platformType: PlatformDetector.currentPlatform,
animationType: AnimationType.fade, // Simple animation
animationDuration: const Duration(milliseconds: 200), // Faster
);
// Desktop-optimized configuration
final desktopConfig = DialogConfig(
dialogType: DialogType.alert,
platformType: PlatformDetector.currentPlatform,
animationType: AnimationType.elastic, // Complex animation
animationDuration: const Duration(milliseconds: 600), // Longer
);
Accessibility #
Built-in Accessibility Features #
- Screen reader support: Comprehensive semantic labeling
- Keyboard navigation: Full desktop keyboard support
- Focus management: Proper focus trapping and restoration
- High contrast support: Theme-aware color schemes
- Touch target sizing: Minimum 48dp touch targets
- Reduced motion: Automatic detection and adaptation
Accessibility Configuration #
final accessibleConfig = DialogConfig(
dialogType: DialogType.alert,
platformType: PlatformDetector.currentPlatform,
semanticLabel: 'Important alert dialog',
animationType: MediaQuery.of(context).accessibleNavigation
? AnimationType.fade
: AnimationType.scale,
);
API Reference #
For complete API documentation, visit pub.flutter-io.cn documentation.
Contributing #
We welcome contributions! Please see our Contributing Guide for details.
Development Setup #
- Fork the repository
- Clone your fork:
git clone https://github.com/yourusername/flutter-adaptive-dialog-manager.git
- Install dependencies:
flutter pub get
- Run the example:
cd example && flutter run
- Make your changes and test thoroughly
- Submit a pull request
License #
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog #
See CHANGELOG.md for a detailed history of changes.
Support #
- Documentation: API Reference
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: bahricanyesildev@gmail.com
Author #
Bahrican Yeşil - GitHub | LinkedIn
Made with ❤️ in Turkey