Neuron class
============================================================================
-
NEURON CORE (Service Locator + Navigation)
Global service locator and navigation manager for Neuron.
The Neuron class serves two primary purposes:
- Service Locator: Manages the lifecycle of NeuronController instances, ensuring they are created once and disposed properly.
- Context-less Navigation: Provides navigation methods that don't require a BuildContext, making navigation cleaner and more testable.
Service Locator Usage
The most common pattern is to use ensure with a static getter in your controller:
class MyController extends NeuronController {
static MyController get init => Neuron.ensure<MyController>(() => MyController());
}
Then in your UI:
final controller = MyController.init; // Returns existing or creates new
Navigation Usage
All navigation methods work without a BuildContext:
Neuron.to(DetailPage()); // Push page
Neuron.off(HomePage()); // Replace page
Neuron.back(); // Pop page
Neuron.toNamed('/settings'); // Named route
See also:
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
- context → BuildContext?
-
Get current context (nullable).
no setter
-
Global navigator key for context-less navigation.
final
Static Methods
-
back<
T> ([T? result]) → void - Pop the current route.
-
backUntil(
bool predicate(Route)) → void - Pop until predicate.
-
clearAll(
) → void - Clears all registered controllers and disposes them.
-
ensure<
T extends NeuronController> (T factory()) → T -
Returns an existing controller of type
Tif present. -
install<
T extends NeuronController> (T controller) → T - Registers a controller and calls its NeuronController.onInit hook.
-
isInstalled<
T extends NeuronController> () → bool -
Returns true if a controller of type
Tis already registered. -
off<
T> (Widget page) → Future< T?> ? -
Replace the current route with
page. -
offNamed<
T extends Object?> (String routeName, {Object? arguments}) → Future< T?> ? - Replace with named route.
-
to<
T> (Widget page, {NeuronPageTransition? transition, Duration? duration, Duration? reverseDuration, Curve? curve, Curve? reverseCurve}) → Future< T?> ? - Push a page on the navigator stack.
-
toNamed<
T> (String routeName, {Object? arguments}) → Future< T?> ? - Push named route.
-
uninstall<
T extends NeuronController> () → void -
Disposes and removes a controller of type
Tif present. -
use<
T extends NeuronController> () → T - Returns an already installed controller.