Implementation
@override
@mustCallSuper
dynamic convert(BuildContext context, Map map, Map? methodMap,
{Domain? domain}) {
var name = map[tag];
if (name == null) {
return WarningWidget(
parentContext: context,
name: name,
error: '$tag is not supported',
url: bundle);
}
try {
if (name == 'Sugar.ifEqual') {
return _buildIfEqual(map, methodMap, context, domain);
} else if (name == 'Sugar.ifEqualBool') {
return _buildIfEqualBool(map, methodMap, context, domain);
} else if (name == 'Sugar.switchCase') {
return _buildSwitchCase(map, methodMap, context, domain);
} else if (name == 'Sugar.nullableIndexedWidgetBuilder') {
return _buildSugarNullableIndexedWidgetBuilder(
context,
map,
methodMap,
domain: domain,
);
} else if (name == 'Sugar.indexedWidgetBuilder') {
return _buildSugarIndexedWidgetBuilder(
context,
map,
methodMap,
domain: domain,
);
} else if (name == 'Sugar.widgetBuilder') {
return _buildSugarWidgetBuilder(
context,
map,
methodMap,
domain: domain,
);
} else if (name == 'Sugar.transitionBuilder') {
return _buildSugarTransitionBuilder(
context,
map,
methodMap,
domain: domain,
);
}
var module = bound?.modules?.moduleOf(name)?.call();
var isWidget = module?.isWidget ?? false;
dynamic mapper = module;
if (mapper == null) {
mapper = bound?.functionOf(name) ?? bound?.valueOf(name);
if (mapper != null) {
return block(map, methodMap, context, domain, mapper, name, false,
forceApply: true);
}
}
if (mapper == null) {
mapper = proxyMirror?.componentOf(name);
final internal = widgetNames.containsKey(name);
isWidget = internal ? (widgetNames[name] ?? false) : true;
}
assert(mapper != null, '$name is not registered!');
if (name == 'Sugar.mapEach') {
return _buildSugarMapEach(mapper, map, methodMap, context, domain);
} else if (name == 'Sugar.map') {
return _buildSugarMap(mapper, map, methodMap, context, domain);
} else if (name == 'Sugar.listBuilder') {
return _buildSugarListBuilder(
name, domain, mapper, map, methodMap, context);
} else if (name == 'Sugar.isNestedScrollViewHeaderSliversBuilder') {
return _buildNestedScrollViewHeaderSlivers(
mapper,
map,
methodMap,
context,
domain,
);
} else if (name == 'Sugar.isButtonStyle') {
return _buildSugarButtonStyle(mapper, map, methodMap, context);
} else if (name == 'Sugar.popMenuButton') {
return _popupMenuBuilder(
mapper,
map,
methodMap,
context,
domain,
);
} else if (name == 'Sugar.sliverChildBuilderDelegate') {
return _buildSugarSliverChildBuilderDelegate(
name,
mapper,
map,
methodMap,
context,
domain,
);
} else if (name == 'Sugar.sliverGridDelegateWithFixedCrossAxisCount') {
return _buildSugarSliverGridDelegateWithFixedCrossAxisCount(
mapper, map, methodMap, context);
}
var source = map['mapEach'];
if (source != null && source is List) {
var children = MapEachDomain(
source,
parent: domain,
).forEach(($, _) {
return block(map, methodMap, context, $, mapper, name, isWidget);
});
return children.asListOf<Widget>() ?? children;
}
return block(map, methodMap, context, domain, mapper, name, isWidget);
} catch (e, stack) {
return WarningWidget(
parentContext: context,
name: name,
error: e,
url: bundle,
stackTrace: stack.toString(),
errorBlock: map,
solution:
"Tag name not supported yet,You need to use the @FairBinding annotation to tag the local Widget component");
}
}