This repository was archived by the owner on May 12, 2022. It is now read-only.

Description
Wouldn't make sense to use the Facade design pattern to extract the external calls for a separated class and import that class on the other dart code that uses it. The logic behind it to call the C function is ugly and extracting for a single class would make your code better.
class OpenMtpLookupFacade {
final DynamicLibrary dyLib;
const OpenMtpLookupFacade() {
dyLib = DynamicLibrary.open(libraryPath);
}
void openModFile(String file) {
final OpenModFile openModFileC = dyLib.lookup<NativeFunction<openModFile_native>>('open_mod_file').asFunction();
openModFileC(file.toNativeUtf8());
}
}
and in the other places:
final openMtp = OpenMtpLookupFacade();
openMtp.openModFile(myFancyString);
For the clients of this class the FFI is totally transparent, they won't know you're calling C :D
|
final OpenModFile openModFileC = dyLib.lookup<NativeFunction<openModFile_native>>('open_mod_file').asFunction(); |