add method

  1. @override
String add(
  1. StateXController? controller
)
inherited

Add a specific StateXController to this View. Returns the StateXController's unique String identifier.

Implementation

@override
String add(StateXController? controller) {
  String id;
  if (controller == null) {
    id = '';
  } else {
    id = super.add(controller); // mixin _ControllersByType
    // Something is not right with that controller.
    if (id.isEmpty) {
      assert(() {
        final type = controller.runtimeType;
        if (_mapControllerByType.containsKey(type)) {
          final con = _mapControllerByType[type];
          if (con != null) {
            assert(
              controller.identifier == con.identifier,
              'Multiple instances of the same Controller class, $type, is not allowed in a StateX class. '
              'They are allowed in the AppStateX class but not in the StateX class. '
              'Either extend the Controller class, $type, or add to AppStateX. '
              "To then retrieve from the 'rootState', use its 'identifier' property. "
              'Controller classes with factory constructors are encouraged instead.',
            );
          }
        }
        return true;
      }());
    } else {
      /// This connects the StateXController to this State object!
      controller._pushStateToSetter(this);
    }
  }
  return id;
}