You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.1 KiB
54 lines
1.1 KiB
|
|
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<EmbedderTexture> createState() => _EmbedderTextureState(); |
|
} |
|
|
|
class _EmbedderTextureState extends State<EmbedderTexture> { |
|
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(); |
|
} |
|
}
|
|
|