(flutter) add const constructor for flutter options

This commit is contained in:
Nick Fisher
2024-09-11 18:01:33 +08:00
parent 9cff791ce5
commit 4e7b79f98d
2 changed files with 15 additions and 8 deletions

View File

@@ -67,7 +67,6 @@ class ThermionFlutterPlugin {
} }
_initializing = true; _initializing = true;
_viewer = await ThermionFlutterPlatform.instance _viewer = await ThermionFlutterPlatform.instance
.createViewer(uberarchivePath: uberArchivePath); .createViewer(uberarchivePath: uberArchivePath);
_appLifecycleListener = AppLifecycleListener( _appLifecycleListener = AppLifecycleListener(
@@ -82,13 +81,14 @@ class ThermionFlutterPlugin {
return _viewer!; return _viewer!;
} }
static Future<ThermionViewer> createViewerWithOptions(ThermionFlutterOptions options) async { static Future<ThermionViewer> createViewerWithOptions(
{ThermionFlutterOptions options = const ThermionFlutterOptions.empty()}) async {
if (_initializing) { if (_initializing) {
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 =
.createViewerWithOptions(options); await ThermionFlutterPlatform.instance.createViewerWithOptions(options);
_appLifecycleListener = AppLifecycleListener( _appLifecycleListener = AppLifecycleListener(
onStateChange: _handleStateChange, onStateChange: _handleStateChange,
); );
@@ -102,7 +102,11 @@ class ThermionFlutterPlugin {
} }
static Future<ThermionFlutterTexture?> createTexture( static Future<ThermionFlutterTexture?> createTexture(
double width, double height, double offsetLeft, double offsetTop, double pixelRatio) async { double width,
double height,
double offsetLeft,
double offsetTop,
double pixelRatio) async {
return ThermionFlutterPlatform.instance return ThermionFlutterPlatform.instance
.createTexture(width, height, offsetLeft, offsetTop, pixelRatio); .createTexture(width, height, offsetLeft, offsetTop, pixelRatio);
} }
@@ -117,8 +121,9 @@ class ThermionFlutterPlugin {
int width, int width,
int height, int height,
int offsetLeft, int offsetLeft,
int offsetTop, double pixelRatio) async { int offsetTop,
return ThermionFlutterPlatform.instance double pixelRatio) async {
.resizeTexture(texture, width, height, offsetLeft, offsetTop, pixelRatio); return ThermionFlutterPlatform.instance.resizeTexture(
texture, width, height, offsetLeft, offsetTop, pixelRatio);
} }
} }

View File

@@ -8,6 +8,8 @@ class ThermionFlutterOptions {
final String? uberarchivePath; final String? uberarchivePath;
ThermionFlutterOptions({this.uberarchivePath}); ThermionFlutterOptions({this.uberarchivePath});
const ThermionFlutterOptions.empty() : uberarchivePath = null;
} }
abstract class ThermionFlutterPlatform extends PlatformInterface { abstract class ThermionFlutterPlatform extends PlatformInterface {