|
|
|
@ -1,8 +1,15 @@
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
|
|
|
|
|
import 'embedder_texture_platform_interface.dart'; |
|
|
|
|
|
|
|
|
|
enum OrientationEvent { |
|
|
|
|
undefined, |
|
|
|
|
portrait, |
|
|
|
|
landscape, |
|
|
|
|
portraitFlipped, |
|
|
|
|
landscapeFlipped, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class EmbedderTexture extends StatefulWidget { |
|
|
|
|
const EmbedderTexture({ |
|
|
|
|
super.key, |
|
|
|
@ -19,8 +26,9 @@ class EmbedderTexture extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
class _EmbedderTextureState extends State<EmbedderTexture> { |
|
|
|
|
int _textureID = 0; |
|
|
|
|
int _camera_width = 0; |
|
|
|
|
int _camera_height = 0; |
|
|
|
|
int _cameraWidth = 0; |
|
|
|
|
int _cameraHeight = 0; |
|
|
|
|
OrientationEvent _orientation = OrientationEvent.undefined; |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
initState() { |
|
|
|
@ -28,13 +36,39 @@ class _EmbedderTextureState extends State<EmbedderTexture> {
|
|
|
|
|
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()); |
|
|
|
|
} |
|
|
|
|
})); |
|
|
|
|
if (mounted) { |
|
|
|
|
_textureID = data['textureId']!; |
|
|
|
|
_cameraWidth = data['width']!; |
|
|
|
|
_cameraHeight = data['height']!; |
|
|
|
|
|
|
|
|
|
switch (data['orientation']!) { |
|
|
|
|
case 0: |
|
|
|
|
_orientation = OrientationEvent.portrait; |
|
|
|
|
break; |
|
|
|
|
case 90: |
|
|
|
|
_orientation = OrientationEvent.landscape; |
|
|
|
|
break; |
|
|
|
|
case 180: |
|
|
|
|
_orientation = OrientationEvent.portraitFlipped; |
|
|
|
|
break; |
|
|
|
|
case 270: |
|
|
|
|
_orientation = OrientationEvent.landscapeFlipped; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
_orientation = OrientationEvent.undefined; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
debugPrint(data.toString()); |
|
|
|
|
} |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
EmbedderTexturePlatform.instance.onChangeOrientation().listen((event) { |
|
|
|
|
setState(() { |
|
|
|
|
if (mounted) { |
|
|
|
|
_orientation = event; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@ -43,34 +77,83 @@ class _EmbedderTextureState extends State<EmbedderTexture> {
|
|
|
|
|
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 = _cameraWidth * widget.height / (widget.width - 40); |
|
|
|
|
// h = widget.width - 40; |
|
|
|
|
// } else { |
|
|
|
|
// w = _cameraHeight.toDouble(); |
|
|
|
|
// h = widget.height - 40 - 56; |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
// return Container( |
|
|
|
|
// color: Colors.black, |
|
|
|
|
// width: widget.width, |
|
|
|
|
// height: widget.height, |
|
|
|
|
// child: RotationTransition( |
|
|
|
|
// turns: AlwaysStoppedAnimation( |
|
|
|
|
// _orientation == OrientationEvent.portrait ? 90 / 360 : 0, |
|
|
|
|
// ), |
|
|
|
|
// child: SizedBox( |
|
|
|
|
// width: w, |
|
|
|
|
// height: h, |
|
|
|
|
// child: Texture(textureId: _textureID), |
|
|
|
|
// ), |
|
|
|
|
// ), |
|
|
|
|
// ); |
|
|
|
|
// } |
|
|
|
|
// return const SizedBox.shrink(); |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
@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); |
|
|
|
|
if (_orientation == OrientationEvent.portrait || |
|
|
|
|
_orientation == OrientationEvent.portraitFlipped) { |
|
|
|
|
w = _cameraWidth * widget.height / (widget.width - 40); |
|
|
|
|
h = widget.width - 40; |
|
|
|
|
} else { |
|
|
|
|
w = _camera_height.toDouble(); |
|
|
|
|
w = _cameraHeight.toDouble(); |
|
|
|
|
h = widget.height - 40 - 56; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AlwaysStoppedAnimation<double>? turns; |
|
|
|
|
|
|
|
|
|
switch (_orientation) { |
|
|
|
|
case OrientationEvent.portrait: |
|
|
|
|
turns = const AlwaysStoppedAnimation(90 / 360); |
|
|
|
|
break; |
|
|
|
|
case OrientationEvent.portraitFlipped: |
|
|
|
|
turns = const AlwaysStoppedAnimation(270 / 360); |
|
|
|
|
break; |
|
|
|
|
case OrientationEvent.landscapeFlipped: |
|
|
|
|
turns = const AlwaysStoppedAnimation(180 / 360); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
turns = const AlwaysStoppedAnimation(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
child: RotationTransition( |
|
|
|
|
turns: turns, |
|
|
|
|
child: SizedBox( |
|
|
|
|
width: w, |
|
|
|
|
height: h, |
|
|
|
|
child: Texture(textureId: _textureID), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|