FlutterEmbedder constructor
FlutterEmbedder(
- Rectangle<
int> size, - DartProject project,
- String flutterLibrary
Creates an instance of the FlutterEmbedder for embedding Flutter in a Windows application.
size
: The dimensions of the embedded Flutter view.project
: Information about the Dart project.flutterLibrary
: The path to the Flutter engine library.
Implementation
FlutterEmbedder(
math.Rectangle<int> size,
DartProject project,
String flutterLibrary,
) {
// Load the Windows engine
final library = DynamicLibrary.open(flutterLibrary);
flutter = FlutterEngineLibrary(library);
// SymInitialize has already been called when Dart starts. When we invoke
// the engine, it's called again, which leads to a "Failed to init
// NativeSymbolResolver (SymInitialize 87)" error. So we clean up before we
// call the engine.
final hProcess = GetCurrentProcess();
SymCleanup(hProcess);
using((arena) {
final engineProperties = arena<FlutterDesktopEngineProperties>();
engineProperties.ref
..aot_library_path =
project.aotLibraryPath.toNativeUtf16(allocator: arena)
..icu_data_path = project.icuDataPath.toNativeUtf16(allocator: arena)
..assets_path = project.assetsPath.toNativeUtf16(allocator: arena);
engine = flutter.FlutterDesktopEngineCreate(engineProperties);
});
messenger = flutter.FlutterDesktopEngineGetMessenger(engine);
if (messenger == nullptr) throw Exception('Failed to create messenger.');
controller = flutter.FlutterDesktopViewControllerCreate(
size.width,
size.height,
engine,
);
if (controller == nullptr) {
throw Exception('Failed to create view controller.');
}
view = flutter.FlutterDesktopViewControllerGetView(controller);
if (view == nullptr) {
throw Exception('Failed to create view from controller.');
}
}