flutter2Native function
Future<void>
flutter2Native(
- FlutterPlatformConfig flutterConfig,
- bool nullSafeSupport, {
- AndroidPlatformConfig? androidConfig,
- IosPlatformConfig? iosConfig,
Implementation
Future<void> flutter2Native(
FlutterPlatformConfig flutterConfig,
bool nullSafeSupport, {
AndroidPlatformConfig? androidConfig,
IosPlatformConfig? iosConfig,
}) async {
Directory directory =
Directory(flutterConfig.sourceCodePath + "/flutter2native");
if (!directory.existsSync()) {
return;
}
List<GenClassBean> list = await platforms_source_gen_init(
flutterConfig.sourceCodePath + "/flutter2native");
await autoCreateJsonParse(list, directory.path, nullSafeSupport);
list.forEach((element) {
element.methods.removeWhere((element) => element.name == "toJson");
});
list.forEach((element) {
var fileConfig = FileConfig.copy(flutterConfig, androidConfig, iosConfig);
//set custom save path
String classPath = element.path.split(":")[1];
classPath = "./lib" + classPath.substring(classPath.indexOf("/"));
Map<int, String> lines = File(classPath).readAsLinesSync().asMap();
for (int index in lines.keys) {
if (index == 0) {
if (lines[index]?.contains("FileConfig") != true) {
Flutter2Native.fileConfigs.add(fileConfig);
break;
}
} else if (lines[index]?.startsWith("//") == true) {
if (lines[index]?.contains("androidSavePath") == true) {
String savePath = lines[index]?.split("=")[1].trim() ?? "";
fileConfig.flutterPlatformConfig.savePath = savePath;
fileConfig.androidPlatformConfig?.savePath = savePath;
// fileConfig.iosPlatformConfig?.savePath = savePath;
} else if (lines[index]?.contains("channelName") == true) {
String channelName = lines[index]?.split("=")[1].trim() ?? "";
fileConfig.flutterPlatformConfig.channelName = channelName;
fileConfig.androidPlatformConfig?.channelName = channelName;
// fileConfig.iosPlatformConfig?.channelName = channelName;
} else if (lines[index]?.contains("packageName") == true) {
String packageName = lines[index]?.split("=")[1].trim() ?? "";
fileConfig.androidPlatformConfig?.packageName = packageName;
}
} else {
Flutter2Native.fileConfigs.add(fileConfig);
break;
}
}
});
Flutter2Native.fileConfigs.asMap().forEach((index, config) {
//if not set packageName, the packageName = channelName
String packageName = config.flutterPlatformConfig.channelName;
if (config.androidPlatformConfig?.packageName.isNotEmpty == true) {
packageName = config.androidPlatformConfig!.packageName;
}
_genFlutterImpl(
[list[index]],
config.flutterPlatformConfig.sourceCodePath,
packageName,
config.flutterPlatformConfig.channelName,
nullSafeSupport,
);
////////////////////////android//////////////////////////
////////////////////////android//////////////////////////
////////////////////////android//////////////////////////
if (androidConfig != null) {
var info = ManagerUtils.managerInfo[config.androidPlatformConfig!.savePath + config.androidPlatformConfig!.channelName];
if (info == null) {
info = ManagerInfo();
ManagerUtils.managerInfo[config.androidPlatformConfig!.savePath + config.androidPlatformConfig!.channelName] = info;
}
info.savePath = config.androidPlatformConfig!.savePath;
info.channelName = config.androidPlatformConfig!.channelName;
info.packageName = packageName.replaceAll(".flutter2native", "");
JavaFileUtils.genJavaCode(
[list[index]],
config.androidPlatformConfig!.packageName,
config.androidPlatformConfig!.savePath,
".flutter2native",
nullSafeSupport: nullSafeSupport);
}
});
////////////////////////ios//////////////////////////
////////////////////////ios//////////////////////////
////////////////////////ios//////////////////////////
if (iosConfig != null) {
ObjcFileUtils.genObjcCode(
list, iosConfig.iosProjectPrefix, iosConfig.savePath, ".flutter2native",
nullSafeSupport: nullSafeSupport);
}
}