getVariables static method

Map<String, dynamic> getVariables(
  1. List<Binding>? bindings,
  2. WidgetModel local,
  3. WidgetModel remote, {
  4. List<String> localAliasNames = const ['this', 'source', 'src'],
  5. List<String> remoteAliasNames = const ['target', 'trg'],
})

Implementation

static Map<String, dynamic> getVariables(
    List<Binding>? bindings, WidgetModel local, WidgetModel remote,
    {List<String> localAliasNames = const ['this', 'source', 'src'],
    List<String> remoteAliasNames = const ['target', 'trg']}) {
  var variables = <String, dynamic>{};

  // get variables
  bindings?.forEach((binding) {
    var key = binding.key;
    var scope = local.scope;
    var name = binding.source.toLowerCase();

    // local alias
    var i = localAliasNames.indexOf(name);
    if (i >= 0) {
      key = key?.replaceFirst(localAliasNames[i], local.id);
      scope = local.scope;
    }

    // remove alias
    i = remoteAliasNames.indexOf(name);
    if (i >= 0) {
      key = key?.replaceFirst(remoteAliasNames[i], remote.id);
      scope = remote.scope;
    }

    // find the observable
    var observable = System.currentApp?.scopeManager.findObservable(scope, key);

    // add to the list
    variables[binding.signature] = binding.translate(observable?.get());
  });

  return variables;
}