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