import 'dart:typed_data'; import 'dart:io'; import 'package:chat/map/location_result.dart'; import 'package:flutter/services.dart'; import 'package:flutter_native_image/flutter_native_image.dart'; //import 'package:flutter_image_compress/flutter_image_compress.dart'; import 'MessageMgr.dart'; import 'file_cache_mgr.dart'; class ScreenShot { static const MethodChannel _channel = const MethodChannel('make.photo.screen.hibok'); static const EventChannel eventChannel = const EventChannel('com.file.hibok'); static Future> takeScreenshotImage() async { Map args = {}; Uint8List bytes = await _channel.invokeMethod('makePhotoScreen', args); File file =await FileCacheMgr().writeFile(DateTime.now().millisecondsSinceEpoch.toString(),bytes); File compressedFile = await FlutterNativeImage.compressImage(file.path, quality: 20, percentage: 80); var compressImg =compressedFile.readAsBytesSync().toList(); // var compressImg = await FlutterImageCompress.compressWithList(bytes, // quality: 20, minWidth: (Screen.width).toInt()); print('地图大小${bytes.length} 压缩后${compressImg.length} '); return compressImg; } static Future getOtherMapAppList() async { Map args = {}; return _channel.invokeMethod('getListForMap', args); } static void openMapForOth(String mapType, LocationResult result) async { Map args = { 'mapType': mapType, 'address': result.address, 'latLng': [result.latLng.latitude, result.latLng.longitude] }; _channel.invokeMethod('openMapForOth', args); } static Future isSupportGoogle() async { Map args = {}; return _channel.invokeMethod('isSupportGoogle', args); } static getFileStream() { eventChannel.receiveBroadcastStream().listen((Object agrs){ print('######## receiveBroadcastStream $agrs'); File file = new File(agrs.toString()); if(file.existsSync()){ print('接收到的文件--存在'); MessageMgr().emit(MessageMgr.RECEIVE_THIRD_SHARE, agrs); }else{ print('接收到的文件--不存在'); } }, onError: (Object error){ print('######## error $error'); }); } }