Pārlūkot izejas kodu

[feat]键盘引导页,增加亲密度设置的引导消息

hezihao 7 mēneši atpakaļ
vecāks
revīzija
2b0948b98f

+ 22 - 19
lib/data/bean/keyboard_guide_msg.dart

@@ -1,27 +1,30 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'keyboard_guide_msg.g.dart';
+
 /// 引导消息实体类
+@JsonSerializable()
 class KeyboardGuideMsg {
   /// 是否是我发的
-  bool isMe = false;
+  @JsonKey(name: 'isMe')
+  bool isMe;
 
   /// 消息内容
-  String content = "";
+  @JsonKey(name: 'content')
+  String content;
+
+  /// 类型
+  @JsonKey(name: "type")
+  String type;
 
   /// 创建时间
-  int createTime = 0;
-
-  KeyboardGuideMsg({required this.isMe, required this.content, required this.createTime});
-
-  KeyboardGuideMsg.fromJson(Map<String, dynamic> json) {
-    isMe = json['isMe'];
-    content = json['content'];
-    createTime = json['createTime'];
-  }
-
-  Map<String, dynamic> toJson() {
-    final Map<String, dynamic> data = <String, dynamic>{};
-    data['isMe'] = isMe;
-    data['content'] = content;
-    data['createTime'] = createTime;
-    return data;
-  }
+  @JsonKey(name: 'createTime')
+  int createTime;
+
+  KeyboardGuideMsg(this.isMe, this.content, this.type, this.createTime);
+
+  factory KeyboardGuideMsg.fromJson(Map<String, dynamic> json) =>
+      _$KeyboardGuideMsgFromJson(json);
+
+  Map<String, dynamic> toJson() => _$KeyboardGuideMsgToJson(this);
 }

+ 23 - 0
lib/data/bean/keyboard_guide_msg.g.dart

@@ -0,0 +1,23 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'keyboard_guide_msg.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+KeyboardGuideMsg _$KeyboardGuideMsgFromJson(Map<String, dynamic> json) =>
+    KeyboardGuideMsg(
+      json['isMe'] as bool,
+      json['content'] as String,
+      json['type'] as String,
+      (json['createTime'] as num).toInt(),
+    );
+
+Map<String, dynamic> _$KeyboardGuideMsgToJson(KeyboardGuideMsg instance) =>
+    <String, dynamic>{
+      'isMe': instance.isMe,
+      'content': instance.content,
+      'type': instance.type,
+      'createTime': instance.createTime,
+    };

+ 26 - 0
lib/module/keyboard_guide/enums/keyboard_guide_msg_type.dart

@@ -0,0 +1,26 @@
+/// 键盘引导消息类型
+enum KeyboardGuideMsgType {
+  /// 普通消息,只展示,不能操作
+  normal("normal"),
+
+  /// 可以复制内容的消息
+  copy("copy"),
+
+  /// 亲密度设置
+  intimacySetting("intimacySetting");
+
+  final String type;
+
+  const KeyboardGuideMsgType(this.type);
+
+  /// 通过状态字符串,获取对应的状态枚举
+  static KeyboardGuideMsgType fromString(String type) {
+    return values.firstWhere(
+      (e) => e.type == type,
+      orElse: () => throw ArgumentError('无效的类型: $type'),
+    );
+  }
+
+  @override
+  String toString() => type;
+}

+ 26 - 12
lib/module/keyboard_guide/keyboard_guide_controller.dart

@@ -1,6 +1,7 @@
 import 'package:flutter/cupertino.dart';
 import 'package:get/get.dart';
 import 'package:injectable/injectable.dart';
+import 'package:keyboard/module/keyboard_guide/enums/keyboard_guide_msg_type.dart';
 import 'package:keyboard/resource/string.gen.dart';
 
 import '../../base/base_controller.dart';
@@ -78,23 +79,35 @@ class KeyboardGuidePageController extends BaseController {
     // 添加一些默认消息
     msgList.add(
       KeyboardGuideMsg(
-        isMe: false,
-        content: StringName.keyboardGuideTaReply1,
-        createTime: DateTime.now().millisecond,
+        false,
+        StringName.keyboardGuideTaReply1,
+        KeyboardGuideMsgType.copy.type,
+        DateTime.now().millisecond,
       ),
     );
     msgList.add(
       KeyboardGuideMsg(
-        isMe: false,
-        content: StringName.keyboardGuideTaReply2,
-        createTime: DateTime.now().millisecond,
+        false,
+        StringName.keyboardGuideTaReply2,
+        KeyboardGuideMsgType.copy.type,
+        DateTime.now().millisecond,
       ),
     );
     msgList.add(
       KeyboardGuideMsg(
-        isMe: false,
-        content: StringName.keyboardGuideTaReply3,
-        createTime: DateTime.now().millisecond,
+        false,
+        StringName.keyboardGuideTaReply3,
+        KeyboardGuideMsgType.copy.type,
+        DateTime.now().millisecond,
+      ),
+    );
+    // 亲密度设置的引导消息
+    msgList.add(
+      KeyboardGuideMsg(
+        false,
+        StringName.keyboardGuideTaReply4,
+        KeyboardGuideMsgType.intimacySetting.type,
+        DateTime.now().millisecond,
       ),
     );
   }
@@ -103,9 +116,10 @@ class KeyboardGuidePageController extends BaseController {
   void _addMsg2List(String msg, bool isMe) {
     msgList.add(
       KeyboardGuideMsg(
-        isMe: isMe,
-        content: msg,
-        createTime: DateTime.now().millisecond,
+        isMe,
+        msg,
+        KeyboardGuideMsgType.normal.type,
+        DateTime.now().millisecond,
       ),
     );
     update();

+ 30 - 13
lib/module/keyboard_guide/keyboard_guide_page.dart

@@ -12,6 +12,7 @@ import '../../resource/colors.gen.dart';
 import '../../resource/string.gen.dart';
 import '../../utils/clipboard_util.dart';
 import '../../utils/url_launcher_util.dart';
+import 'enums/keyboard_guide_msg_type.dart';
 
 /// 键盘引导页面
 class KeyboardGuidePage extends BasePage<KeyboardGuidePageController> {
@@ -198,7 +199,7 @@ class KeyboardGuidePage extends BasePage<KeyboardGuidePageController> {
   /// 构建聊天气泡
   Widget _buildMsgBubble(KeyboardGuideMsg msg) {
     // 设置气泡的外边距,让气泡不易过长
-    double marginValue = 59.0;
+    double marginValue = 35.0;
     EdgeInsets marginEdgeInsets;
     if (msg.isMe) {
       marginEdgeInsets = EdgeInsets.only(left: marginValue);
@@ -236,8 +237,10 @@ class KeyboardGuidePage extends BasePage<KeyboardGuidePageController> {
           borderRadius: bgBorderRadius,
         ),
         child: Row(
+          // 宽高包裹内容
           mainAxisSize: MainAxisSize.min,
-          crossAxisAlignment: CrossAxisAlignment.start,
+          // 图标和文本,垂直居中
+          crossAxisAlignment: CrossAxisAlignment.center,
           children: [
             Flexible(
               // 消息文本
@@ -252,20 +255,11 @@ class KeyboardGuidePage extends BasePage<KeyboardGuidePageController> {
                 softWrap: true,
               ),
             ),
-            // 只有对方发送的,才有复制按钮
+            // 只有对方发送的,才有操作按钮
             if (!msg.isMe)
               Padding(
                 padding: EdgeInsets.only(left: 8.0),
-                child: GestureDetector(
-                  onTap: () {
-                    // 复制内容到剪切板
-                    ClipboardUtil.copyToClipboard(msg.content);
-                  },
-                  child: Assets.images.iconCopy.image(
-                    width: 18.w,
-                    height: 18.w,
-                  ),
-                ),
+                child: _buildMsgActionBtn(msg),
               ),
           ],
         ),
@@ -273,6 +267,29 @@ class KeyboardGuidePage extends BasePage<KeyboardGuidePageController> {
     );
   }
 
+  /// 消息操作按钮
+  Widget _buildMsgActionBtn(KeyboardGuideMsg msg) {
+    if (msg.type == KeyboardGuideMsgType.copy.type) {
+      return GestureDetector(
+        onTap: () {
+          // 复制内容到剪切板
+          ClipboardUtil.copyToClipboard(msg.content);
+        },
+        child: Assets.images.iconCopy.image(width: 18.w, height: 18.w),
+      );
+    } else if (msg.type == KeyboardGuideMsgType.intimacySetting.type) {
+      return GestureDetector(
+        onTap: () {
+          // 跳转到亲密度设置页
+          // TODO hezihao,需要志鹏提供路由路径,才能跳转到亲密度设置页
+        },
+        child: Assets.images.iconSetting.image(width: 18.w, height: 18.w),
+      );
+    } else {
+      return SizedBox.shrink();
+    }
+  }
+
   /// 构建聊天消息列表项
   Widget _buildMsgItem(KeyboardGuideMsg msg) {
     Widget content;