FeaturePlugin class abstract
Base class for all feature plugins in the application.
Feature plugins are self-contained modules that provide specific functionality to the application. Each plugin has access to various registries for hooks, addons, widgets, adapters, actions, and the event bus for inter-plugin communication.
Plugin Lifecycle:
- Creation: Plugin instance is created via factory function
- Configuration Check: PluginRegistry checks if plugin is active in environment.json
- Registration: If active, onRegister() is called for setup
- Initialization: onInit() is called for async setup (API connections, etc.)
- Start: onStart() is called once all plugins finished initialization
- Runtime: onAppLifecycle() is called for app foreground/background changes
- Stop: onStop() is called during app teardown
Configuration:
Plugins can be configured in environment.json under the plugins key:
{
"plugins": {
"products": {
"active": true,
"settings": {
"cache": {
"productsTTL": 300,
"categoriesTTL": 600
}
},
"sections": {
"main": [...]
}
}
}
}
Example Implementation:
class ProductsPlugin extends FeaturePlugin {
@override
String get name => 'products';
@override
String get version => '1.0.0';
@override
void onRegister() {
// Register widgets
widgetRegistry.register('product.list', (context, {data, onEvent}) {
return ProductListWidget(data: data);
});
// Register adapters
adapterRegistry.registerProductsAdapter(WooProductsAdapter());
}
@override
Future<void> onInit() async {
// Async initialization (API setup, cache warming, etc.)
await loadInitialData();
}
@override
Map<String, WidgetBuilder>? getRoutes() {
return {
'/products': (context) => ProductsScreen(),
'/product': (context) => ProductDetailScreen(),
};
}
}
Constructors
Properties
- actionRegistry → ActionRegistry
-
no setter
- adapterRegistry → AdapterRegistry
-
no setter
- addonRegistry → AddonRegistry
-
no setter
- appContext ↔ MooseAppContext
-
Injected by PluginRegistry.register before onRegister is called.
All registry access goes through this scoped context.
getter/setter pair
-
bottomTabs
→ List<
BottomTab> -
Optional: Bottom navigation tabs exposed by this plugin.
no setter
- cache → CacheManager
-
no setter
- configManager → ConfigManager
-
no setter
-
configSchema
→ Map<
String, dynamic> -
JSON Schema for plugin configuration validation.
no setter
- eventBus → EventBus
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hookRegistry → HookRegistry
-
no setter
- logger → AppLogger
-
no setter
- name → String
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- version → String
-
no setter
- widgetRegistry → WidgetRegistry
-
no setter
Methods
-
getDefaultSettings(
) → Map< String, dynamic> - Returns default settings for this plugin.
-
getRoutes(
) → Map< String, WidgetBuilder> ? - Optional: Plugin can provide routes
-
getSetting<
T> (String key) → T -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onAppLifecycle(
AppLifecycleState state) → Future< void> - Called when the app lifecycle changes.
-
onInit(
) → Future< void> - Called when plugin needs to be initialized.
-
onRegister(
) → void - Called when plugin is registered
-
onStart(
) → Future< void> - Called after all plugins have finished onInit.
-
onStop(
) → Future< void> - Called during app teardown.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited