提交 142949be authored 作者: 张国庆's avatar 张国庆

修改通依赖注入初始化控制器

上级 946b4ca0
import 'package:clx_flutter_message/util/string_util.dart';
import 'package:clx_flutter_message/util/toast_util.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'clx_flutter_message_platform_interface.dart';
import 'common/constant.dart';
import 'core/model/message_config.dart';
import 'core/model/message_data.dart';
import 'core/notice/notice_dialog_widget.dart';
import 'core/notice/notice_manager.dart';
import 'core/notification/notification_layout/notification_layout_widget.dart';
import 'core/notification/notification_manager.dart';
import 'core/socket/socket_io.dart';
......@@ -123,6 +126,14 @@ abstract class BaseMessageConfig with NotificationManager, NoticeManager {
onJumpToMessagePage(page, arguments);
}
// 构造方法
BaseMessageConfig() {
//通过getx 注入 NotificationLayoutController
Get.put(NotificationLayoutController());
//通过getx 注入 NoticeDialogWidgetController
Get.put(NoticeDialogWidgetController());
}
//刷新消息、获取未处理消息,重新连接websocket
Future<void> refreshMessage(BuildContext context) async {
// 校验消息相关配置字段
......@@ -160,6 +171,5 @@ abstract class BaseMessageConfig with NotificationManager, NoticeManager {
setNotification(nList);
// 处理公告
setNotice(aList);
}
}
......@@ -14,7 +14,5 @@ class MessageConfig {
String accessToken = "";
BaseMessageConfig? baseMessageConfig;
BaseMessageConfig? messageManagement;
}
......@@ -176,7 +176,6 @@ class NoticeDialogWidget extends GetView<NoticeDialogWidgetController> {
@override
Widget build(BuildContext context) {
return GetBuilder<NoticeDialogWidgetController>(
init: NoticeDialogWidgetController(),
id: "NoticeDialogWidget",
builder: (_) {
return _buildView();
......@@ -187,7 +186,7 @@ class NoticeDialogWidget extends GetView<NoticeDialogWidgetController> {
class NoticeDialogWidgetController extends GetxController {
NoticeDialogWidgetController();
BaseMessageConfig? messageDeal = messageConfig.baseMessageConfig;
BaseMessageConfig? messageDeal = messageConfig.messageManagement;
_initData() {
update(["NoticeDialogWidget"]);
}
......
......@@ -14,7 +14,6 @@ class NotificationLayoutWidget extends GetView<NotificationLayoutController> {
@override
Widget build(BuildContext context) {
return GetBuilder<NotificationLayoutController>(
init: NotificationLayoutController(),
id: "NotificationLayoutWidget",
builder: (_) {
if (controller.headNode == null) {
......@@ -104,7 +103,7 @@ class NotificationLayoutController extends GetxController {
MessageNode? headNode;
BaseMessageConfig? messageDeal=messageConfig.baseMessageConfig;
BaseMessageConfig? messageDeal = messageConfig.messageManagement;
_initData() {
update(["NotificationLayoutWidget"]);
......@@ -174,11 +173,9 @@ class NotificationLayoutController extends GetxController {
update();
}
@override
void onReady() {
super.onReady();
_initData();
}
}
import 'package:flutter/cupertino.dart';
import '../../util/extension.dart';
import '../model/message_data.dart';
import 'notification_layout/notification_layout_widget.dart';
......@@ -7,22 +8,22 @@ import 'notification_layout/notification_layout_widget.dart';
mixin NotificationManager {
OverlayEntry? _overlayEntry;
final NotificationLayoutWidget _notificationLayoutWidget =
const NotificationLayoutWidget();
final NotificationLayoutController? _controller =
findOtherLogic<NotificationLayoutController>();
/// 显示悬浮布局
void showNotification(BuildContext? context) {
if (context == null) return;
if (_overlayEntry != null) return; // 防止重复显示
if (_notificationLayoutWidget.controller.headNode == null) {
if (_controller?.headNode == null) {
return; // 防止没有消息时显示
}
_overlayEntry = OverlayEntry(
builder: (context) => Positioned(
builder: (context) => const Positioned(
top: 0,
left: 0,
right: 0,
child: _notificationLayoutWidget,
child: NotificationLayoutWidget(),
),
);
......@@ -37,16 +38,16 @@ mixin NotificationManager {
/// 缓存之前的消息列表
void setNotification(List<dynamic> data) {
_notificationLayoutWidget.controller.setCashMessage(
_controller?.setCashMessage(
data.map<MessageData>((e) => MessageData.fromJson(e)).toList(),
);
}
void insertNotification(MessageData data) {
_notificationLayoutWidget.controller.insertNotification(data);
_controller?.insertNotification(data);
}
void clear() {
_notificationLayoutWidget.controller.clear();
_controller?.clear();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论