diff --git a/lib/filament_controller.dart b/lib/filament_controller.dart index 7861eb3d..9ff4f553 100644 --- a/lib/filament_controller.dart +++ b/lib/filament_controller.dart @@ -95,7 +95,7 @@ abstract class FilamentController { /// 5) The FilamentWidget will replace the empty Container with a Texture widget /// If you need to wait until a FilamentViewer has been created, listen to the [viewer] stream. /// - void createViewer(int width, int height); + Future createViewer(int width, int height); /// /// Resize the viewport & backing texture. diff --git a/lib/filament_controller_ffi.dart b/lib/filament_controller_ffi.dart index 8d4f554d..1faa6be3 100644 --- a/lib/filament_controller_ffi.dart +++ b/lib/filament_controller_ffi.dart @@ -112,7 +112,8 @@ class FilamentControllerFFI extends FilamentController { /// /// Called by `FilamentWidget`. You do not need to call this yourself. /// - void createViewer(int width, int height) async { + @override + Future createViewer(int width, int height) async { if (_viewer != null) { throw Exception( "Viewer already exists, make sure you call destroyViewer first"); diff --git a/lib/widgets/filament_widget.dart b/lib/widgets/filament_widget.dart index 763d6a09..dd4046e0 100644 --- a/lib/widgets/filament_widget.dart +++ b/lib/widgets/filament_widget.dart @@ -71,12 +71,6 @@ class _FilamentWidgetState extends State { @override void initState() { WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { - // when attaching a debugger via Android Studio on startup, this can delay presentation of the widget - // (meaning the widget may attempt to create a viewer with size 0x0). - // we just add a small delay here which should avoid this - if (!kReleaseMode) { - await Future.delayed(Duration(seconds: 2)); - } var size = ((context.findRenderObject()) as RenderBox).size; _width = size.width.ceil(); _height = size.height.ceil(); @@ -139,14 +133,11 @@ class _SizedFilamentWidgetState extends State<_SizedFilamentWidget> { ); WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { - // when attaching a debugger via Android Studio on startup, this can delay presentation of the widget - // (meaning the widget may attempt to create a viewer with size 0x0). - // we just add a small delay here which should avoid this if (!kReleaseMode) { await Future.delayed(Duration(seconds: 2)); } try { - widget.controller.createViewer(widget.width, widget.height); + await widget.controller.createViewer(widget.width, widget.height); } catch (err) { _error = err.toString(); } @@ -264,7 +255,9 @@ class _SizedFilamentWidgetState extends State<_SizedFilamentWidget> { } if (widget.controller.textureDetails == null || _resizeTimer != null) { - return widget.initial ?? Container(color: Colors.red); + return Stack(children: [ + Positioned.fill(child: widget.initial ?? Container(color: Colors.red)) + ]); } // see [FilamentControllerFFI.resize] for an explanation of how we deal with resizing var texture = Texture(