Browse Source

1、新增颜色逻辑测试使用

bakamaka.guan 2 years ago
parent
commit
78bd8e778d
1 changed files with 27 additions and 2 deletions
  1. 27 2
      lib/components/white_board/white_board.dart

+ 27 - 2
lib/components/white_board/white_board.dart

@@ -12,6 +12,7 @@ class FWhiteBoard extends StatefulWidget implements FWidget {
     key,
     required this.initData,
     required this.userId,
+    required this.patientColor,
     required this.paintType,
     required this.sendData,
     required this.onReceiveData,
@@ -24,6 +25,9 @@ class FWhiteBoard extends StatefulWidget implements FWidget {
   /// 用户id
   final String userId;
 
+  /// 用户颜色
+  final Color patientColor;
+
   /// 当前绘制模式
   final PaintType paintType;
 
@@ -49,7 +53,7 @@ class _FWhiteBoardState extends State<FWhiteBoard> {
   WhiteBoardPen myPen = WhiteBoardPen();
 
   /// 当前用户的画笔颜色
-  Color get myPenColor => ColorUtil.generateColor(widget.userId);
+  Color get myPenColor => widget.patientColor;
 
   /// 固定的画笔粗细
   static const double strokeWidth = 3.0;
@@ -142,10 +146,31 @@ class _FWhiteBoardState extends State<FWhiteBoard> {
     widget.sendData(jsonEncode({
       "u_Id": widget.userId, // 用户id
       "l_Id": "", // 线id
+      "color": widget.patientColor.toString(), // 线的颜色
       "points": PointsUtil.compressPointsList(pointsList),
     }));
   }
 
+  Color parseColor(String colorString) {
+    if (colorString == null || !colorString.startsWith('Color(')) {
+      return Colors.black54;
+    }
+    final String valueString = colorString.substring(6, colorString.length - 1);
+    List<String> parts = valueString.split(',');
+    if (parts.length != 4) {
+      return Colors.black54;
+    }
+    try {
+      int alpha = int.parse(parts[0]);
+      int red = int.parse(parts[1]);
+      int green = int.parse(parts[2]);
+      int blue = int.parse(parts[3]);
+      return Color.fromARGB(alpha, red, green, blue);
+    } catch (e) {
+      return Colors.black54;
+    }
+  }
+
   /// 接收绘制数据【如果存在数据正在绘制,其他的加入绘制队列,等待当前绘制完成继续绘制】
   void _onReceiveDrawData(String jsonData) async {
     if (_asyncDrawLock) {
@@ -156,7 +181,7 @@ class _FWhiteBoardState extends State<FWhiteBoard> {
     var data = jsonDecode(jsonData);
     List<dynamic> pointsList = PointsUtil.decompressPointsList(data["points"]);
     Line line = Line(
-      color: ColorUtil.generateColor(data["u_Id"]),
+      color: parseColor(data["color"]),
       strokeWidth: strokeWidth,
       userId: data["u_Id"],
     );