Further restructuring of chatBubble.dart, added chatMessage.dart
This commit is contained in:
@ -2,8 +2,8 @@ import 'package:bubble/bubble.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatResponse.dart';
|
||||
import 'package:marianum_mobile/screen/pages/talk/chatMessage.dart';
|
||||
|
||||
import '../../../api/marianumcloud/talk/chat/richObjectStringProcessor.dart';
|
||||
import '../../../api/marianumcloud/talk/room/getRoomResponse.dart';
|
||||
|
||||
class ChatBubble {
|
||||
@ -11,7 +11,7 @@ class ChatBubble {
|
||||
color: Color(0xffd4eaf4),
|
||||
borderWidth: 1,
|
||||
elevation: 2,
|
||||
margin: BubbleEdges.only(top: 15),
|
||||
margin: BubbleEdges.only(bottom: 15),
|
||||
alignment: Alignment.center,
|
||||
);
|
||||
|
||||
@ -21,7 +21,7 @@ class ChatBubble {
|
||||
color: seamless ? Colors.transparent : Colors.white,
|
||||
borderWidth: seamless ? 0 : 1,
|
||||
elevation: seamless ? 0 : 1,
|
||||
margin: const BubbleEdges.only(top: 15, left: 10, right: 50),
|
||||
margin: const BubbleEdges.only(bottom: 15, left: 10, right: 50),
|
||||
alignment: Alignment.topLeft,
|
||||
);
|
||||
}
|
||||
@ -32,7 +32,7 @@ class ChatBubble {
|
||||
color: seamless ? Colors.transparent : const Color(0xffd9fdd3),
|
||||
borderWidth: seamless ? 0 : 1,
|
||||
elevation: seamless ? 0 : 1,
|
||||
margin: const BubbleEdges.only(top: 15, right: 10, left: 50),
|
||||
margin: const BubbleEdges.only(bottom: 15, right: 10, left: 50),
|
||||
alignment: Alignment.topRight,
|
||||
);
|
||||
}
|
||||
@ -41,50 +41,48 @@ class ChatBubble {
|
||||
bool isSender;
|
||||
GetChatResponseObject bubbleData;
|
||||
GetRoomResponseObject chatData;
|
||||
late ChatMessage message;
|
||||
|
||||
ChatBubble({
|
||||
required this.context,
|
||||
required this.isSender,
|
||||
required this.bubbleData,
|
||||
required this.chatData,
|
||||
});
|
||||
}) {
|
||||
message = ChatMessage(originalMessage: bubbleData.message, originalData: bubbleData.messageParameters);
|
||||
}
|
||||
|
||||
BubbleStyle getStyle() {
|
||||
BubbleStyle currentStyle;
|
||||
if(bubbleData.messageType == GetRoomResponseObjectMessageType.comment) {
|
||||
if(isSender) {
|
||||
currentStyle = getStyleSelf(bubbleData.messageParameters?.containsKey("file") ?? false);
|
||||
return getStyleSelf(message.containsFile);
|
||||
} else {
|
||||
currentStyle = getStyleOther(bubbleData.messageParameters?.containsKey("file") ?? false);
|
||||
return getStyleOther(message.containsFile);
|
||||
}
|
||||
} else {
|
||||
currentStyle = styleSystem;
|
||||
return styleSystem;
|
||||
}
|
||||
|
||||
return currentStyle;
|
||||
}
|
||||
|
||||
Bubble generateBubble() {
|
||||
|
||||
bool showActorDisplayName = bubbleData.messageType == GetRoomResponseObjectMessageType.comment && chatData.type != GetRoomResponseObjectConversationType.oneToOne;
|
||||
bool showBubbleTime = bubbleData.messageType != GetRoomResponseObjectMessageType.system;
|
||||
var _actorTextStyle = TextStyle(color: Theme.of(context).primaryColor, fontWeight: FontWeight.bold);
|
||||
var actorTextStyle = TextStyle(color: Theme.of(context).primaryColor, fontWeight: FontWeight.bold);
|
||||
|
||||
return Bubble(
|
||||
margin: BubbleEdges.only(/*bottom: element == data.getChatResponse.sortByTimestamp().last ? 20 : 0*/),
|
||||
|
||||
style: getStyle(),
|
||||
child: Container(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: MediaQuery.of(context).size.width * 0.9,
|
||||
minWidth: showActorDisplayName ? _textSize(bubbleData.actorDisplayName, _actorTextStyle).width : 30,
|
||||
minWidth: showActorDisplayName ? _textSize(bubbleData.actorDisplayName, actorTextStyle).width : 30,
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(bottom: showBubbleTime ? 18 : 0, top: showActorDisplayName ? 18 : 0),
|
||||
child: FutureBuilder(
|
||||
future: RichObjectStringProcessor.parseAnyToWidget(bubbleData.message, bubbleData.messageParameters),
|
||||
future: message.getWidget(),
|
||||
builder: (context, snapshot) {
|
||||
if(!snapshot.hasData) return const CircularProgressIndicator();
|
||||
return snapshot.data ?? const Icon(Icons.error);
|
||||
@ -99,7 +97,7 @@ class ChatBubble {
|
||||
child: Text(
|
||||
bubbleData.actorDisplayName,
|
||||
textAlign: TextAlign.start,
|
||||
style: _actorTextStyle,
|
||||
style: actorTextStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user