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.
79 lines
1.9 KiB
79 lines
1.9 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; |
|
int _camera_width = 0; |
|
int _camera_height = 0; |
|
|
|
@override |
|
initState() { |
|
super.initState(); |
|
EmbedderTexturePlatform.instance |
|
.create(widget.width, widget.height) |
|
.then((data) => setState(() { |
|
if (mounted) { |
|
_textureID = data['textureId']!; |
|
_camera_width = data['width']!; |
|
_camera_height = data['height']!; |
|
debugPrint(_textureID.toString()); |
|
} |
|
})); |
|
} |
|
|
|
@override |
|
void dispose() { |
|
super.dispose(); |
|
EmbedderTexturePlatform.instance.remove(_textureID); |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
if (_textureID != 0) { |
|
|
|
double w = 0; |
|
double h = 0; |
|
|
|
if (MediaQuery.of(context).orientation == Orientation.portrait) { |
|
w = _camera_width * widget.height / (widget.width - 40); |
|
h = widget.width - 40; |
|
} else { |
|
w = _camera_height.toDouble(); |
|
h = widget.height - 40 - 56; |
|
} |
|
|
|
return Container( |
|
color: Colors.black, |
|
width: widget.width, |
|
height: widget.height, |
|
child: Center( |
|
child: RotationTransition( |
|
turns: AlwaysStoppedAnimation(MediaQuery.of(context).orientation == Orientation.portrait ? 90 / 360 : 0), |
|
child: SizedBox( |
|
width: w, |
|
height: h, |
|
child: Texture(textureId: _textureID) |
|
), |
|
) |
|
), |
|
); |
|
} |
|
return const SizedBox.shrink(); |
|
} |
|
}
|
|
|