import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'texture_rgba_renderer_platform_interface.dart'; /// An implementation of [TextureRgbaRendererPlatform] that uses method channels. class MethodChannelTextureRgbaRenderer extends TextureRgbaRendererPlatform { /// The method channel used to interact with the native platform. @visibleForTesting final methodChannel = const MethodChannel('texture_rgba_renderer'); @override Future getPlatformVersion() async { final version = await methodChannel.invokeMethod('getPlatformVersion'); return version; } @override Future createTexture(int key) async { return await methodChannel .invokeMethod('createTexture', {"key": key}) ?? -1; } @override Future closeTexture(int key) async { return await methodChannel .invokeMethod('closeTexture', {"key": key}) ?? false; } @override Future onRgba(int key, Uint8List data, int height, int width) async { return await methodChannel.invokeMethod('onRgba', {"data": data, "height": height, "width": width, "key": key}) ?? false; } @override Future getTexturePtr(int key) async { // TODO: currently only supports Windows. if (!Platform.isWindows) { return -1; } final ptr = await methodChannel.invokeMethod('getTexturePtr', {"key": key}) ?? false; return ptr; } }