#36 Fixed overflowing message time

This commit is contained in:
Elias Müller 2024-03-05 19:21:12 +01:00
parent 4a8e528cb8
commit 3f779072e3
2 changed files with 31 additions and 22 deletions

12
lib/extensions/text.dart Normal file
View File

@ -0,0 +1,12 @@
import 'package:flutter/material.dart';
extension TextExt on Text {
Size get size {
final TextPainter textPainter = TextPainter(
text: TextSpan(text: data, style: style),
maxLines: 1,
textDirection: TextDirection.ltr
)..layout(minWidth: 0, maxWidth: double.infinity);
return textPainter.size;
}
}

View File

@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:jiffy/jiffy.dart';
import 'package:marianum_mobile/extensions/text.dart';
import 'package:provider/provider.dart';
import '../../../../api/marianumcloud/talk/chat/getChatResponse.dart';
@ -80,15 +81,6 @@ class _ChatBubbleState extends State<ChatBubble> {
double downloadProgress = 0;
Future<DownloaderCore>? downloadCore;
Size _textSize(String text, TextStyle style) {
final TextPainter textPainter = TextPainter(
text: TextSpan(text: text, style: style),
maxLines: 1,
textDirection: TextDirection.ltr)
..layout(minWidth: 0, maxWidth: double.infinity);
return textPainter.size;
}
BubbleStyle getStyle() {
if(widget.bubbleData.messageType == GetRoomResponseObjectMessageType.comment) {
if(widget.isSender) {
@ -107,7 +99,19 @@ class _ChatBubbleState extends State<ChatBubble> {
message = ChatMessage(originalMessage: widget.bubbleData.message, originalData: widget.bubbleData.messageParameters);
bool showActorDisplayName = widget.bubbleData.messageType == GetRoomResponseObjectMessageType.comment && widget.chatData.type != GetRoomResponseObjectConversationType.oneToOne;
bool showBubbleTime = widget.bubbleData.messageType != GetRoomResponseObjectMessageType.system;
var actorTextStyle = TextStyle(color: Theme.of(context).primaryColor, fontWeight: FontWeight.bold);
Text actorText = Text(
widget.bubbleData.actorDisplayName,
textAlign: TextAlign.start,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: Theme.of(context).primaryColor, fontWeight: FontWeight.bold),
);
Text timeText = Text(
Jiffy.parseFromMillisecondsSinceEpoch(widget.bubbleData.timestamp * 1000).format(pattern: "HH:mm"),
textAlign: TextAlign.end,
style: const TextStyle(color: Colors.grey, fontSize: 12),
);
return Column(
mainAxisSize: MainAxisSize.min,
@ -122,7 +126,9 @@ class _ChatBubbleState extends State<ChatBubble> {
child: Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.9,
minWidth: showActorDisplayName ? _textSize(widget.bubbleData.actorDisplayName, actorTextStyle).width : 30,
minWidth: showActorDisplayName
? actorText.size.width
: timeText.size.width,
),
child: Stack(
children: [
@ -135,12 +141,7 @@ class _ChatBubbleState extends State<ChatBubble> {
child: Positioned(
top: 0,
left: 0,
child: Text(
widget.bubbleData.actorDisplayName,
textAlign: TextAlign.start,
overflow: TextOverflow.ellipsis,
style: actorTextStyle,
),
child: actorText
),
),
Visibility(
@ -148,11 +149,7 @@ class _ChatBubbleState extends State<ChatBubble> {
child: Positioned(
bottom: 0,
right: 0,
child: Text(
Jiffy.parseFromMillisecondsSinceEpoch(widget.bubbleData.timestamp * 1000).format(pattern: "HH:mm"),
textAlign: TextAlign.end,
style: const TextStyle(color: Colors.grey, fontSize: 12),
),
child: timeText
),
),
Visibility(