Browse Source

修改扩展参数

ios
Jolie 3 months ago
parent
commit
e3dffe6b34
5 changed files with 74 additions and 57 deletions
  1. 27
      lib/im/im_manager.dart
  2. 26
      lib/widget/message/image_item.dart
  3. 26
      lib/widget/message/text_item.dart
  4. 26
      lib/widget/message/video_item.dart
  5. 26
      lib/widget/message/voice_item.dart

27
lib/im/im_manager.dart

@ -203,31 +203,24 @@ class IMManager {
}
//
// API operatorId attributes
// attributes revenueInfo
//
if (message.direction == MessageDirection.RECEIVE) {
try {
double? coinValue;
String? revenueInfo;
// 1 attributes
// attributes revenueInfo
if (message.attributes != null) {
final coinValueStr = message.attributes!['coin_value'] as String?;
if (coinValueStr != null && coinValueStr.isNotEmpty) {
coinValue = double.tryParse(coinValueStr);
}
}
// 2 attributes operatorId
if (coinValue == null && operatorId.isNotEmpty) {
coinValue = double.tryParse(operatorId);
revenueInfo = message.attributes!['revenueInfo'] as String?;
}
// attributes
if (coinValue != null && coinValue > 0) {
// revenueInfo attributes UI显示
if (revenueInfo != null && revenueInfo.isNotEmpty) {
if (message.attributes == null) {
message.attributes = {};
}
message.attributes!['coin_value'] = coinValue.toString();
// revenueInfo coin_value 便UI组件可以直接使用
message.attributes!['coin_value'] = revenueInfo;
// ChatController
final fromId = message.from;
@ -240,7 +233,7 @@ class IMManager {
controller.messages[index] = message;
controller.update();
if (Get.isLogEnable) {
Get.log('✅ [IMManager] 已更新接收消息的金币数值: msgId=${message.msgId}, coinValue=$coinValue');
Get.log('✅ [IMManager] 已更新接收消息的金币信息: msgId=${message.msgId}, revenueInfo=$revenueInfo');
}
}
}
@ -248,7 +241,7 @@ class IMManager {
}
} catch (e) {
if (Get.isLogEnable) {
Get.log('⚠️ [IMManager] 处理金币数值失败: $e');
Get.log('⚠️ [IMManager] 处理金币信息失败: $e');
}
}
}

26
lib/widget/message/image_item.dart

@ -232,8 +232,8 @@ class _ImageItemState extends State<ImageItem> {
@override
Widget build(BuildContext context) {
//
final coinValue = _getCoinValue();
//
final revenueInfo = _getRevenueInfo();
return Column(
children: [
@ -286,10 +286,10 @@ class _ImageItemState extends State<ImageItem> {
),
),
//
if (!widget.isSentByMe && coinValue != null)
if (!widget.isSentByMe && revenueInfo != null)
Padding(
padding: EdgeInsets.only(top: 10.h),
child: _buildCoinLabel(coinValue),
child: _buildCoinLabel(revenueInfo),
),
],
),
@ -651,14 +651,20 @@ class _ImageItemState extends State<ImageItem> {
}
}
//
double? _getCoinValue() {
// revenueInfo coin_value
String? _getRevenueInfo() {
try {
final attributes = widget.message.attributes;
if (attributes != null && attributes.containsKey('coin_value')) {
if (attributes != null) {
// revenueInfo
final revenueInfo = attributes['revenueInfo'] as String?;
if (revenueInfo != null && revenueInfo.isNotEmpty) {
return revenueInfo;
}
// revenueInfo coin_value revenueInfo
final coinValueStr = attributes['coin_value'] as String?;
if (coinValueStr != null && coinValueStr.isNotEmpty) {
return double.tryParse(coinValueStr);
return coinValueStr;
}
}
} catch (e) {
@ -668,7 +674,7 @@ class _ImageItemState extends State<ImageItem> {
}
//
Widget _buildCoinLabel(double coinValue) {
Widget _buildCoinLabel(String revenueInfo) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h),
decoration: BoxDecoration(
@ -685,7 +691,7 @@ class _ImageItemState extends State<ImageItem> {
),
SizedBox(width: 4.w),
Text(
'+${coinValue.toStringAsFixed(2)}',
revenueInfo,
style: TextStyle(
fontSize: 12.sp,
color: Color.fromRGBO(255, 132, 0, 1),

26
lib/widget/message/text_item.dart

@ -25,8 +25,8 @@ class TextItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
//
final coinValue = _getCoinValue();
//
final revenueInfo = _getRevenueInfo();
return Column(
children: [
@ -82,10 +82,10 @@ class TextItem extends StatelessWidget {
),
),
//
if (!isSentByMe && coinValue != null)
if (!isSentByMe && revenueInfo != null)
Padding(
padding: EdgeInsets.only(top: 10.h),
child: _buildCoinLabel(coinValue),
child: _buildCoinLabel(revenueInfo),
),
],
),
@ -135,14 +135,20 @@ class TextItem extends StatelessWidget {
);
}
//
double? _getCoinValue() {
// revenueInfo coin_value
String? _getRevenueInfo() {
try {
final attributes = message.attributes;
if (attributes != null && attributes.containsKey('coin_value')) {
if (attributes != null) {
// revenueInfo
final revenueInfo = attributes['revenueInfo'] as String?;
if (revenueInfo != null && revenueInfo.isNotEmpty) {
return revenueInfo;
}
// revenueInfo coin_value revenueInfo
final coinValueStr = attributes['coin_value'] as String?;
if (coinValueStr != null && coinValueStr.isNotEmpty) {
return double.tryParse(coinValueStr);
return coinValueStr;
}
}
} catch (e) {
@ -152,7 +158,7 @@ class TextItem extends StatelessWidget {
}
//
Widget _buildCoinLabel(double coinValue) {
Widget _buildCoinLabel(String revenueInfo) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h),
decoration: BoxDecoration(
@ -169,7 +175,7 @@ class TextItem extends StatelessWidget {
),
SizedBox(width: 4.w),
Text(
'+${coinValue.toStringAsFixed(2)}',
revenueInfo,
style: TextStyle(
fontSize: 12.sp,
color: Color.fromRGBO(255, 132, 0, 1),

26
lib/widget/message/video_item.dart

@ -203,8 +203,8 @@ class _VideoItemState extends State<VideoItem> {
@override
Widget build(BuildContext context) {
//
final coinValue = _getCoinValue();
//
final revenueInfo = _getRevenueInfo();
return Column(
children: [
@ -376,10 +376,10 @@ class _VideoItemState extends State<VideoItem> {
],
),
//
if (!widget.isSentByMe && coinValue != null)
if (!widget.isSentByMe && revenueInfo != null)
Padding(
padding: EdgeInsets.only(top: 10.h),
child: _buildCoinLabel(coinValue),
child: _buildCoinLabel(revenueInfo),
),
],
),
@ -459,14 +459,20 @@ class _VideoItemState extends State<VideoItem> {
}
}
//
double? _getCoinValue() {
// revenueInfo coin_value
String? _getRevenueInfo() {
try {
final attributes = widget.message.attributes;
if (attributes != null && attributes.containsKey('coin_value')) {
if (attributes != null) {
// revenueInfo
final revenueInfo = attributes['revenueInfo'] as String?;
if (revenueInfo != null && revenueInfo.isNotEmpty) {
return revenueInfo;
}
// revenueInfo coin_value revenueInfo
final coinValueStr = attributes['coin_value'] as String?;
if (coinValueStr != null && coinValueStr.isNotEmpty) {
return double.tryParse(coinValueStr);
return coinValueStr;
}
}
} catch (e) {
@ -476,7 +482,7 @@ class _VideoItemState extends State<VideoItem> {
}
//
Widget _buildCoinLabel(double coinValue) {
Widget _buildCoinLabel(String revenueInfo) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h),
decoration: BoxDecoration(
@ -493,7 +499,7 @@ class _VideoItemState extends State<VideoItem> {
),
SizedBox(width: 4.w),
Text(
'+${coinValue.toStringAsFixed(2)}',
revenueInfo,
style: TextStyle(
fontSize: 12.sp,
color: Color.fromRGBO(255, 132, 0, 1),

26
lib/widget/message/voice_item.dart

@ -235,8 +235,8 @@ class _VoiceItemState extends State<VoiceItem> with TickerProviderStateMixin {
//
final isPlaying = _playerManager.isPlaying(widget.messageId);
//
final coinValue = _getCoinValue();
//
final revenueInfo = _getRevenueInfo();
return Column(
children: [
@ -309,10 +309,10 @@ class _VoiceItemState extends State<VoiceItem> with TickerProviderStateMixin {
_handlePlayPause();
}),
//
if (!widget.isSentByMe && coinValue != null)
if (!widget.isSentByMe && revenueInfo != null)
Padding(
padding: EdgeInsets.only(top: 10.h),
child: _buildCoinLabel(coinValue),
child: _buildCoinLabel(revenueInfo),
),
],
),
@ -355,15 +355,21 @@ class _VoiceItemState extends State<VoiceItem> with TickerProviderStateMixin {
);
}
//
double? _getCoinValue() {
// revenueInfo coin_value
String? _getRevenueInfo() {
try {
if (widget.message != null) {
final attributes = widget.message!.attributes;
if (attributes != null && attributes.containsKey('coin_value')) {
if (attributes != null) {
// revenueInfo
final revenueInfo = attributes['revenueInfo'] as String?;
if (revenueInfo != null && revenueInfo.isNotEmpty) {
return revenueInfo;
}
// revenueInfo coin_value revenueInfo
final coinValueStr = attributes['coin_value'] as String?;
if (coinValueStr != null && coinValueStr.isNotEmpty) {
return double.tryParse(coinValueStr);
return coinValueStr;
}
}
}
@ -374,7 +380,7 @@ class _VoiceItemState extends State<VoiceItem> with TickerProviderStateMixin {
}
//
Widget _buildCoinLabel(double coinValue) {
Widget _buildCoinLabel(String revenueInfo) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h),
decoration: BoxDecoration(
@ -391,7 +397,7 @@ class _VoiceItemState extends State<VoiceItem> with TickerProviderStateMixin {
),
SizedBox(width: 4.w),
Text(
'+${coinValue.toStringAsFixed(2)}',
revenueInfo,
style: TextStyle(
fontSize: 12.sp,
color: Color.fromRGBO(255, 132, 0, 1),

Loading…
Cancel
Save