controller.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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/talks.dart';
  12. import '../../../data/bean/template_bean.dart';
  13. import '../controller.dart';
  14. class MindMapController extends BaseController {
  15. final String? talkId;
  16. MindMapController(this.talkId);
  17. TalkController get talkController => Get.find<TalkController>(tag: talkId);
  18. List<TemplateBean>? get templateList => talkController.templateList.value;
  19. int? get templateSelectId => talkController.templateSelectId.value;
  20. RxBool get isShowMindFullScreen => talkController.isShowMindFullScreen;
  21. StreamSubscription? _talkSummaryListener;
  22. StreamSubscription? _talkStatusListener;
  23. GlobalKey repaintKey = GlobalKey();
  24. bool _isWebViewLoaded = false;
  25. @override
  26. void onReady() async {
  27. super.onReady();
  28. _talkStatusListener =
  29. talkController.talkBean.value?.status.listen((status) {
  30. if (status == TalkStatus.analysisSuccess) {
  31. _dealTalkSummaryUpdate(talkController.talkBean.value?.summary.value);
  32. }
  33. });
  34. _dealTalkSummaryUpdate(talkController.talkBean.value?.summary.value);
  35. _talkSummaryListener =
  36. talkController.talkBean.value?.summary.listen((summary) {
  37. _dealTalkSummaryUpdate(summary);
  38. });
  39. }
  40. void _loadWebMindData(String summary) {
  41. talkController.webViewController.loadFlutterAsset(Assets.html.index);
  42. talkController.webViewController.setNavigationDelegate(
  43. NavigationDelegate(
  44. onPageFinished: (String url) async {
  45. _isWebViewLoaded = true;
  46. _callUpdateMind(summary);
  47. },
  48. onNavigationRequest: (NavigationRequest request) {
  49. return NavigationDecision.navigate;
  50. },
  51. ),
  52. );
  53. }
  54. void _callUpdateMind(String summary) {
  55. talkController.webViewController
  56. .callHandler(MindUtil.functionToJsUpdateMind, args: [summary],
  57. handler: (value) {
  58. debugPrint('_dealTalkSummaryUpdate mindMap update success: $value');
  59. });
  60. }
  61. void _updateMindData(String summary) {
  62. if (_isWebViewLoaded) {
  63. _callUpdateMind(summary);
  64. } else {
  65. _loadWebMindData(summary);
  66. }
  67. }
  68. void _dealTalkSummaryUpdate(String? summary) {
  69. if (summary == null ||
  70. summary.isEmpty ||
  71. talkController.talkBean.value?.status.value !=
  72. TalkStatus.analysisSuccess) {
  73. return;
  74. }
  75. _updateMindData(summary);
  76. }
  77. void addTemplateClick() {}
  78. void fullScreenClick() {
  79. talkController.isShowMindFullScreen.value = true;
  80. }
  81. void exitFullScreenClick() {
  82. talkController.onExitMindFullScreen();
  83. }
  84. @override
  85. void onClose() {
  86. super.onClose();
  87. _talkStatusListener?.cancel();
  88. _talkSummaryListener?.cancel();
  89. }
  90. }