stateUpdated method

dynamic stateUpdated(
  1. dynamic data
)

When you call updateState, this method will be called within your State. The data parameter will contain any data passed from the updateState method.

E.g. updateState('my_state', data: "Hello World");

stateUpdated(dynamic data) { data = "Hello World" }

Implementation

stateUpdated(dynamic data) async {
  if (data is! Map) return;
  if (!data.containsKey('action') || data['action'] == null) return;
  dynamic stateData = {};
  if (data['data'] != null) {
    stateData = data['data'];
  }
  switch (data['action']) {
    case 'refresh-page':
      {
        Function()? setStateData = stateData['setState'];
        if (setStateData != null) {
          setState(() {
            setStateData();
          });
          return;
        }
        reboot();
        break;
      }
    case 'pop':
      {
        dynamic result = stateData['result'];
        if (result != null) {
          pop(result: result);
          return;
        }
        pop();
        break;
      }
    case 'validate':
      {
        validate(
            rules: stateData['rules'],
            data: stateData['data'],
            onSuccess: stateData['onSuccess'],
            messages: stateData['messages'],
            showAlert: stateData['showAlert'],
            alertDuration: stateData['alertDuration'],
            alertStyle: stateData['alertStyle'],
            onFailure: stateData['onFailure'],
            lockRelease: stateData['lockRelease']);
        break;
      }
    case 'toast-success':
      {
        showToastSuccess(
            title: stateData['title'],
            description: stateData['description'],
            style: stateData['style']);
        break;
      }
    case 'toast-warning':
      {
        showToastWarning(
            title: stateData['title'],
            description: stateData['description'],
            style: stateData['style']);
        break;
      }
    case 'toast-info':
      {
        showToastInfo(
            title: stateData['title'],
            description: stateData['description'],
            style: stateData['style']);
        break;
      }
    case 'toast-oops':
      {
        showToastInfo(
            title: stateData['title'],
            description: stateData['description'],
            style: stateData['style']);
        break;
      }
    case 'toast-danger':
      {
        showToastDanger(
            title: stateData['title'],
            description: stateData['description'],
            style: stateData['style']);
        break;
      }
    case 'toast-sorry':
      {
        showToastSorry(
            title: stateData['title'],
            description: stateData['description'],
            style: stateData['style']);
        break;
      }
    case 'toast-custom':
      {
        showToastCustom(
            title: stateData['title'],
            description: stateData['description'],
            style: stateData['style']);
        break;
      }
    case 'change-language':
      {
        changeLanguage(stateData['language'],
            restartState: stateData['restartState']);
        break;
      }
    case 'lock-release':
      {
        lockRelease(stateData['name'],
            perform: stateData['perform'],
            shouldSetState: stateData['shouldSetState']);
        break;
      }
    case 'confirm-action':
      {
        confirmAction(stateData['action'],
            title: stateData['title'], dismissText: stateData['dismissText']);
        break;
      }
    case 'set-state':
      {
        Function()? setStateData = stateData['setState'];
        if (setStateData != null) {
          setState(() {
            setStateData();
          });
          return;
        }
      }
    default:
      {}
  }
}