import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:path_provider/path_provider.dart'; import 'package:electronic_assistant/base/base_controller.dart'; import 'package:electronic_assistant/module/talk/mindmap/mind_util.dart'; import 'package:electronic_assistant/resource/assets.gen.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'package:get/get.dart'; import 'package:get/get_core/src/get_main.dart'; import 'package:webview_flutter/webview_flutter.dart'; import '../../../data/bean/template_bean.dart'; import '../controller.dart'; class MindMapController extends BaseController { final String? talkId; MindMapController(this.talkId); TalkController get talkController => Get.find(tag: talkId); List? get templateList => talkController.templateList.value; int? get templateSelectId => talkController.templateSelectId.value; RxBool get isShowMindFullScreen => talkController.isShowMindFullScreen; StreamSubscription? _talkSummaryListener; GlobalKey repaintKey = GlobalKey(); @override void onReady() async { super.onReady(); // await talkController.webViewController // .loadRequest(Uri.parse('http://192.168.10.144:9528/')); // await talkController.webViewController.loadFlutterAsset(Assets.images.test); // talkController.webViewController.setBackgroundColor(Colors.blue); talkController.webViewController.loadFlutterAsset(Assets.html.index); talkController.webViewController.setNavigationDelegate( NavigationDelegate( onPageFinished: (String url) async { _dealTalkSummaryUpdate(talkController.talkBean.value?.summary.value); }, onNavigationRequest: (NavigationRequest request) { return NavigationDecision.navigate; }, ), ); _talkSummaryListener = talkController.talkBean.value?.summary.listen((summary) { _dealTalkSummaryUpdate(summary); }); } // // Capture WebView content as a PNG image // Future _captureAndSaveScreenshot() async { // try { // // Render the content inside RepaintBoundary to a picture // RenderRepaintBoundary boundary = repaintKey.currentContext! // .findRenderObject() as RenderRepaintBoundary; // var image = await boundary.toImage( // pixelRatio: 3); // Higher pixel ratio for better quality // // // Convert the image to byte data // ByteData? byteData = await image.toByteData(format: ImageByteFormat.png); // Uint8List uint8List = byteData!.buffer.asUint8List(); // // // Get the path to save the image // final directory = await getApplicationDocumentsDirectory(); // final path = '${directory.path}/webview_screenshot.png'; // // // Save the file // final file = File(path); // await file.writeAsBytes(uint8List); // // print('Screenshot saved at $path'); // } catch (e) { // print("Error taking screenshot: $e"); // } // } void _dealTalkSummaryUpdate(String? summary) { debugPrint('mindMap summary: $summary'); talkController.webViewController .callHandler(MindUtil.functionToJsUpdateMind, args: [summary], handler: (value) { debugPrint('mindMap summary: $value'); }); } void addTemplateClick() {} void fullScreenClick() { talkController.isShowMindFullScreen.value = true; } void exitFullScreenClick() { talkController.onExitMindFullScreen(); } @override void onClose() { super.onClose(); _talkSummaryListener?.cancel(); } }