import 'package:embedder_texture/embedder_texture.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'embedder_texture_platform_interface.dart'; /// An implementation of [LinuxOpenglPlatform] that uses method channels. class MethodChannelEmbedderTexture extends EmbedderTexturePlatform { /// The method channel used to interact with the native platform. @visibleForTesting final methodChannel = const MethodChannel('embedder_texture'); @override Future> create(double width, double height) async { final data = await methodChannel.invokeMethod?>('create', { 'width': width.round(), 'height': height.round(), }); return data ?? {}; } @override Future remove(int textureId) async { return await methodChannel.invokeMethod('remove', { 'textureId': textureId, }) ?? false; } @override Stream onChangeOrientation() async* { await for (final orientation in const EventChannel('embedder_texture_orientation') .receiveBroadcastStream()) { switch (orientation) { case 0: yield OrientationEvent.portrait; break; case 90: yield OrientationEvent.landscape; break; case 180: yield OrientationEvent.portraitFlipped; break; case 270: yield OrientationEvent.landscapeFlipped; break; default: yield OrientationEvent.undefined; } } } }