pluggy 0.0.5
pluggy: ^0.0.5 copied to clipboard
A Flutter package that provides general-purpose services, tools, and features for Flutter applications.
Pluggy #
A Flutter package providing general-purpose services, tools, and utilities for Flutter applications.
Features #
- AlertService: Show SnackBars and BottomSheets from anywhere in your app (context-less navigation).
- SmartAlert: Modern, stacking toast notifications that appear on the bottom-right overlay.
Installation #
Add this to your pubspec.yaml:
dependencies:
pluggy: ^0.0.4
Quick Start #
// AlertService
import 'package:pluggy/services/alert_service/alert_service.dart';
import 'package:pluggy/services/alert_service/alert_service_config.dart';
// SmartAlert
import 'package:pluggy/services/alert_service/smart_alert.dart';
void main() {
final navigatorKey = GlobalKey<NavigatorState>();
// Initialize Services
SmartAlert.init(navigatorKey);
AlertServiceConfig().initialize(navigatorKey: navigatorKey);
runApp(MaterialApp(
navigatorKey: navigatorKey,
home: const MyHomePage(),
));
}
void examples() {
// AlertService
AlertService.showSnackBar("Hello World!");
// SmartAlert
SmartAlert.show(AlertType.success, 'Success', 'Operation completed');
}
Usage #
AlertService #
To use AlertService, you must initialize AlertServiceConfig with a GlobalKey<NavigatorState> before using any methods. This allows showing alerts without passing a BuildContext.
import 'package:pluggy/services/alert_service/alert_service.dart';
import 'package:pluggy/services/alert_service/alert_service_config.dart';
void main() {
final navigatorKey = GlobalKey<NavigatorState>();
// Initialize Configuration
AlertServiceConfig().initialize(navigatorKey: navigatorKey);
runApp(MaterialApp(
navigatorKey: navigatorKey,
home: Home(),
));
}
// Usage anywhere in the app
void showMessage() {
AlertService.showSnackBar("Hello World!");
AlertService.showBottomSheet("Title", "Message Content");
}
SmartAlert #
SmartAlert provides stacking toast notifications that automatically dismiss. It requires initialization with the same navigatorKey.
import 'package:pluggy/services/alert_service/smart_alert.dart';
void main() {
final navigatorKey = GlobalKey<NavigatorState>();
SmartAlert.init(navigatorKey);
runApp(MaterialApp(
navigatorKey: navigatorKey,
home: const MyHomePage(),
));
}
void showSmartAlerts() {
SmartAlert.show(AlertType.success, 'Success', 'Operation successful');
SmartAlert.show(AlertType.error, 'Error', 'Something went wrong');
SmartAlert.show(AlertType.warning, 'Warning', 'Please be careful');
SmartAlert.show(AlertType.info, 'Info', 'Just so you know');
}
// Dismiss all active alerts
void dismissAll() {
SmartAlert.dismissAll();
}
Troubleshooting #
"AlertService: No navigatorKey or context available" #
This error occurs if AlertServiceConfig has not been initialized or if the navigatorKey is not attached to the MaterialApp.
Solution:
Ensure you initialize the config in your main() function:
AlertServiceConfig().initialize(navigatorKey: navigatorKey);
License #
This project is licensed under the MIT License.