create method
创建目标实例
Implementation
Target create(L10nSheet sheetData) {
final targetNode = settings.targetNode;
final outputDirPath = settings.outputDirPath;
final name = switch (targetNode) {
final String e => e,
{'name': final String e} => e,
_ => throw const TargetSettingsError(),
};
T possibleTargetValue<T>(String key, {required T defaultValue}) {
if (targetNode is MapBase) {
return (targetNode[key] as T?) ?? defaultValue;
} else {
return defaultValue;
}
}
try {
switch (name) {
case 'getx':
return GetX(
sheetData: sheetData,
outputDirPath: outputDirPath,
);
case 'arb':
return Arb(
sheetData: sheetData,
outputDirPath: outputDirPath,
genL10nYaml: possibleTargetValue(
'genL10nYaml',
defaultValue: false,
),
);
case 'localizations':
return Localizations(
sheetData: sheetData,
outputDirPath: outputDirPath,
className: possibleTargetValue(
'className',
defaultValue: 'L',
),
outputFileName: possibleTargetValue(
'outputFileName',
defaultValue: 'app_localizations',
),
genExtension: possibleTargetValue(
'genExtension',
defaultValue: false,
),
);
}
} catch (e) {
if (e is TargetSettingsError) rethrow;
throw TargetSettingsError(name, e.toString());
}
throw UnsupportedTargetError(name);
}