From 9a87eb4d9b0301594e831915382a6ef58e4b553e Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Thu, 5 Sep 2024 22:21:09 +0800 Subject: [PATCH] feat: allow passing null options to ThermionWidget --- .../lib/thermion/widgets/thermion_widget.dart | 2 +- .../lib/thermion/widgets/thermion_widget_web_impl.dart | 9 ++++++--- .../lib/thermion/widgets/thermion_widget_web_stub.dart | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/thermion_flutter/thermion_flutter/lib/thermion/widgets/thermion_widget.dart b/thermion_flutter/thermion_flutter/lib/thermion/widgets/thermion_widget.dart index c903e7a4..d0a6bf94 100644 --- a/thermion_flutter/thermion_flutter/lib/thermion/widgets/thermion_widget.dart +++ b/thermion_flutter/thermion_flutter/lib/thermion/widgets/thermion_widget.dart @@ -95,7 +95,7 @@ class _ThermionWidgetState extends State { return ResizeObserver( onResized: _resizeTexture, child: ThermionWidgetWeb( - options: widget.options! as ThermionFlutterWebOptions)); + options: widget.options as ThermionFlutterWebOptions?)); } if (_texture?.usesBackingWindow == true) { diff --git a/thermion_flutter/thermion_flutter/lib/thermion/widgets/thermion_widget_web_impl.dart b/thermion_flutter/thermion_flutter/lib/thermion/widgets/thermion_widget_web_impl.dart index 752f5116..e1302aba 100644 --- a/thermion_flutter/thermion_flutter/lib/thermion/widgets/thermion_widget_web_impl.dart +++ b/thermion_flutter/thermion_flutter/lib/thermion/widgets/thermion_widget_web_impl.dart @@ -6,13 +6,16 @@ import 'package:web/web.dart'; import 'package:flutter/widgets.dart'; class ThermionWidgetWeb extends StatelessWidget { - final ThermionFlutterWebOptions options; + + late final ThermionFlutterWebOptions options; - const ThermionWidgetWeb({super.key, required this.options}); + const ThermionWidgetWeb({super.key, ThermionFlutterWebOptions? options}) { + this.options = options ?? ThermionFlutterWebOptions(); + } @override Widget build(BuildContext context) { - if (options.importCanvasAsWidget) { + if (options?.importCanvasAsWidget == true) { return _ImageCopyingWidget(); } return Container(color: const Color(0x00000000)); diff --git a/thermion_flutter/thermion_flutter/lib/thermion/widgets/thermion_widget_web_stub.dart b/thermion_flutter/thermion_flutter/lib/thermion/widgets/thermion_widget_web_stub.dart index db61a5b5..01514bb8 100644 --- a/thermion_flutter/thermion_flutter/lib/thermion/widgets/thermion_widget_web_stub.dart +++ b/thermion_flutter/thermion_flutter/lib/thermion/widgets/thermion_widget_web_stub.dart @@ -4,7 +4,7 @@ import 'package:thermion_flutter_ffi/thermion_flutter_ffi.dart'; import 'package:thermion_flutter_web/thermion_flutter_web_options.dart'; class ThermionWidgetWeb extends StatefulWidget { - final ThermionFlutterWebOptions options; + final ThermionFlutterWebOptions? options; const ThermionWidgetWeb({super.key, required this.options});