feat: add createViewerWithOptions to ThermionFlutterPlugin and mark createViewer as deprecated

This commit is contained in:
Nick Fisher
2024-09-05 17:47:41 +08:00
parent cf0a76c343
commit 0d71b0d8fe

View File

@@ -65,8 +65,29 @@ class ThermionFlutterPlugin {
throw Exception("Existing call to createViewer has not completed."); throw Exception("Existing call to createViewer has not completed.");
} }
_initializing = true; _initializing = true;
_viewer = await ThermionFlutterPlatform.instance _viewer = await ThermionFlutterPlatform.instance
.createViewer(uberArchivePath: uberArchivePath); .createViewer(uberarchivePath: uberArchivePath);
_appLifecycleListener = AppLifecycleListener(
onStateChange: _handleStateChange,
);
_viewer!.onDispose(() async {
_viewer = null;
_appLifecycleListener?.dispose();
_appLifecycleListener = null;
});
_initializing = false;
return _viewer!;
}
static Future<ThermionViewer> createViewerWithOptions(ThermionFlutterOptions options) async {
if (_initializing) {
throw Exception("Existing call to createViewer has not completed.");
}
_initializing = true;
_viewer = await ThermionFlutterPlatform.instance
.createViewerWithOptions(options);
_appLifecycleListener = AppLifecycleListener( _appLifecycleListener = AppLifecycleListener(
onStateChange: _handleStateChange, onStateChange: _handleStateChange,
); );
@@ -80,9 +101,9 @@ class ThermionFlutterPlugin {
} }
static Future<ThermionFlutterTexture?> createTexture( static Future<ThermionFlutterTexture?> createTexture(
double width, double height, double offsetLeft, double offsetRight, double pixelRatio) async { double width, double height, double offsetLeft, double offsetTop, double pixelRatio) async {
return ThermionFlutterPlatform.instance return ThermionFlutterPlatform.instance
.createTexture(width, height, offsetLeft, offsetRight, pixelRatio); .createTexture(width, height, offsetLeft, offsetTop, pixelRatio);
} }
static Future destroyTexture(ThermionFlutterTexture texture) async { static Future destroyTexture(ThermionFlutterTexture texture) async {
@@ -95,8 +116,8 @@ class ThermionFlutterPlugin {
int width, int width,
int height, int height,
int offsetLeft, int offsetLeft,
int offsetRight) async { int offsetTop, double pixelRatio) async {
return ThermionFlutterPlatform.instance return ThermionFlutterPlatform.instance
.resizeTexture(texture, width, height, offsetLeft, offsetRight); .resizeTexture(texture, width, height, offsetLeft, offsetTop, pixelRatio);
} }
} }