controller.dart 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:electronic_assistant/base/base_controller.dart';
  4. import 'package:electronic_assistant/module/talk/mindmap/mind_util.dart';
  5. import 'package:electronic_assistant/resource/assets.gen.dart';
  6. import 'package:flutter/rendering.dart';
  7. import 'package:flutter/widgets.dart';
  8. import 'package:get/get.dart';
  9. import 'package:get/get_core/src/get_main.dart';
  10. import 'package:webview_flutter/webview_flutter.dart';
  11. import '../../../data/bean/template_bean.dart';
  12. import '../controller.dart';
  13. class MindMapController extends BaseController {
  14. final String? talkId;
  15. MindMapController(this.talkId);
  16. TalkController get talkController => Get.find<TalkController>(tag: talkId);
  17. List<TemplateBean>? get templateList => talkController.templateList.value;
  18. int? get templateSelectId => talkController.templateSelectId.value;
  19. RxBool get isShowMindFullScreen => talkController.isShowMindFullScreen;
  20. StreamSubscription? _talkSummaryListener;
  21. GlobalKey repaintKey = GlobalKey();
  22. @override
  23. void onReady() async {
  24. super.onReady();
  25. talkController.webViewController.loadFlutterAsset(Assets.html.index);
  26. talkController.webViewController.setNavigationDelegate(
  27. NavigationDelegate(
  28. onPageFinished: (String url) async {
  29. _dealTalkSummaryUpdate(talkController.talkBean.value?.summary.value);
  30. },
  31. onNavigationRequest: (NavigationRequest request) {
  32. return NavigationDecision.navigate;
  33. },
  34. ),
  35. );
  36. _talkSummaryListener =
  37. talkController.talkBean.value?.summary.listen((summary) {
  38. _dealTalkSummaryUpdate(summary);
  39. });
  40. }
  41. void _dealTalkSummaryUpdate(String? summary) {
  42. debugPrint('mindMap summary: $summary');
  43. talkController.webViewController
  44. .callHandler(MindUtil.functionToJsUpdateMind, args: [summary],
  45. handler: (value) {
  46. debugPrint('mindMap update success: $value');
  47. });
  48. }
  49. void addTemplateClick() {}
  50. void fullScreenClick() {
  51. talkController.isShowMindFullScreen.value = true;
  52. }
  53. void exitFullScreenClick() {
  54. talkController.onExitMindFullScreen();
  55. }
  56. @override
  57. void onClose() {
  58. super.onClose();
  59. _talkSummaryListener?.cancel();
  60. }
  61. }