Magic class
The Magic Facade.
This is your global entry point to the Magic framework. Instead of
accessing MagicApp.instance directly, you can use the cleaner Magic
facade for common operations.
Service Container Access
// Bind a service
Magic.bind('api', () => ApiService());
// Register a singleton
Magic.singleton('cache', () => CacheManager());
// Resolve a service
final api = Magic.make<ApiService>('api');
Global UI Feedback (Context-Free!)
Magic.snackbar('Success', 'User created!');
Magic.dialog(ConfirmDialog());
Magic.loading();
Magic.closeLoading();
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
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- app → MagicApp
-
Get the application container instance.
no setter
-
controllers
→ Iterable<
Object> -
All controllers currently registered via put (or findOrPut).
no setter
- isLoading → bool
-
Check if a loading dialog is currently shown.
no setter
- view → MagicViewRegistry
-
Access the view registry to customize UI components.
no setter
Static Methods
-
bind(
String key, Function closure, {}) → void - Bind a service into the container.
-
boot(
) → Future< void> - Boot all registered service providers.
-
bound(
String key) → bool - Check if a service is bound in the container.
-
closeDialog(
) → void - Close the currently open dialog.
-
closeLoading(
) → void - Close the loading dialog.
-
confirm(
{required String title, required String message, String confirmText = 'Confirm', String cancelText = 'Cancel', bool isDangerous = false}) → Future< bool> - Show a confirmation dialog.
-
delete<
T> () → void - Delete a controller.
-
dialog<
T> (Widget dialog, {bool barrierDismissible = true}) → Future< T?> - Show a custom dialog.
-
error(
String title, String message) → void - Show an error snackbar.
-
find<
T> () → T - Find a controller by type.
-
findOrPut<
T> (T builder()) → T - Find a controller or register it if not found.
-
flush(
) → void - Flush the container (useful for testing).
-
init(
{String envFileName = '.env', List< Map< configs = const [], List<String, dynamic> >Map< configFactories = const [], List<String, dynamic> Function()>ServiceProvider> providers = const []}) → Future<void> - Initialize the Magic framework.
-
isRegistered<
T> () → bool - Check if a controller exists.
-
loading(
{String? message}) → void - Show a loading dialog.
-
make<
T> (String key) → T - Resolve a service from the container.
-
put<
T> (T controller) → T - Register a controller instance.
-
register(
ServiceProvider provider) → Future< void> - Register a service provider.
-
reload(
) → void - Restart the application.
-
seed(
List< Seeder> seeders) → Future<void> - Run database seeders.
-
singleton(
String key, Function closure) → void - Register a singleton service.
-
snackbar(
String title, String message, {String type = 'info', Duration? duration}) → void - Show a snackbar notification.
-
success(
String title, String message) → void - Show a success snackbar.
-
toast(
String message, {Duration duration = const Duration(seconds: 2)}) → void - Show a toast notification.