import 'package:flutter/material.dart'; import 'embedder_texture_platform_interface.dart'; class EmbedderTexture extends StatefulWidget { const EmbedderTexture({ super.key, required this.width, required this.height, }); final double width; final double height; @override State createState() => _EmbedderTextureState(); } class _EmbedderTextureState extends State { int _textureID = 0; @override initState() { super.initState(); EmbedderTexturePlatform.instance .create(widget.width, widget.height) .then((value) => setState(() { if (mounted) { _textureID = value!; } })); } @override void dispose() { super.dispose(); EmbedderTexturePlatform.instance.remove(_textureID); } @override Widget build(BuildContext context) { if (_textureID != 0) { return SizedBox( width: widget.width, height: widget.height, child: Center( child: Texture(textureId: _textureID) ), ); } return const SizedBox.shrink(); } }