import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:no_screenshot/constants.dart'; import 'package:no_screenshot/screenshot_snapshot.dart'; import 'no_screenshot_platform_interface.dart'; /// An implementation of [NoScreenshotPlatform] that uses method channels. class MethodChannelNoScreenshot extends NoScreenshotPlatform { /// The method channel used to interact with the native platform. @visibleForTesting final methodChannel = const MethodChannel(screenshotMethodChannel); @visibleForTesting final eventChannel = const EventChannel(screenshotEventChannel); @override Stream get screenshotStream { return eventChannel.receiveBroadcastStream().map((event) => ScreenshotSnapshot.fromMap(jsonDecode(event) as Map)); } @override Future toggleScreenshot() async { final result = await methodChannel.invokeMethod(toggleScreenShotConst); return result ?? false; } @override Future screenshotOff() async { final result = await methodChannel.invokeMethod(screenShotOffConst); return result ?? false; } @override Future screenshotOn() async { final result = await methodChannel.invokeMethod(screenShotOnConst); return result ?? false; } @override Future toggleScreenshotWithImage() async { final result = await methodChannel.invokeMethod(screenSetImage); return result ?? false; } @override Future startScreenshotListening() { return methodChannel.invokeMethod(startScreenshotListeningConst); } @override Future stopScreenshotListening() { return methodChannel.invokeMethod(stopScreenshotListeningConst); } @override Future startScreenRecordingListening() { return methodChannel.invokeMethod(startScreenRecordingListeningConst); } @override Future stopScreenRecordingListening() { return methodChannel.invokeMethod(stopScreenRecordingListeningConst); } }