Empire<T extends EmpireViewModel> class Null safety

Used to provide shared state and functions across specific scopes of your application, or the entire application itself.

The viewModel should contain any state or functionality that is required by one or more child widgets. See viewModelOf for information on accessing the view model.

onAppStateChanged is required and should return a unique String value each time it is called. This is used to determine whether the EmpireApp inherited widget needs to be updated, therefore updating all it's child widgets. Consider using the Uuid package.

If you are implementing your own unique string mechanism, know that if it generates the same value twice in a row, your second change will not be reflected in the application until a new, unique value is generated.

Example Using Uuid

import 'package:uuid/uuid.dart';

Empire(
 myViewModel,
 child: HomePage(),
 onAppStateChanged: () => Uuid().v1(),
)

Nested / Scoped Empires

Empire(
 MyApplicationViewModel(),
 onAppStateChanged: () => Uuid().v1(),
 child: MaterialApp(
  title: 'My App',
  home: Scaffold(
    backgroundColor: Empire.viewModelOf<MyApplicationViewModel>().backgroundColor.value,
    child: Empire(
      MyHomePageViewModel(),
      onAppStateChanged: () => Uuid().v1(),
      child: Builder(builder: (innerContext){
        return Center(
          child: Text(${Empire.viewModelOf<MyHomePageViewModel>().title.value})
        );
      }),
    )
  )
 )
)

Inheritance

Constructors

Empire(T viewModel, {Key? key, required Widget child, required String onAppStateChanged(), bool debugPrintStateChanges = false})
const

Properties

child Widget
final
debugPrintStateChanges bool
final
hashCode int
The hash code for this object.
@nonVirtual, read-only, inherited
key Key?
Controls how one widget replaces another widget in the tree.
final, inherited
onAppStateChanged String Function()
final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
viewModel → T
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<Empire<EmpireViewModel>>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
@protected, inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
@nonVirtual, inherited

Static Methods

of<T extends EmpireViewModel>(BuildContext context) EmpireApp<T>
Gets the instance of the EmpireApp that matches the generic type argument T.
viewModelOf<T extends EmpireViewModel>(BuildContext context) → T
Gets the EmpireViewModel from the EmpireApp that matches the generic type argument T.