Improve message bubble design
This commit is contained in:
parent
fae2bd4eed
commit
c7371acb13
|
@ -4,6 +4,7 @@ import 'package:fluffychat/components/message_content.dart';
|
||||||
import 'package:fluffychat/components/reply_content.dart';
|
import 'package:fluffychat/components/reply_content.dart';
|
||||||
import 'package:fluffychat/i18n/i18n.dart';
|
import 'package:fluffychat/i18n/i18n.dart';
|
||||||
import 'package:fluffychat/utils/date_time_extension.dart';
|
import 'package:fluffychat/utils/date_time_extension.dart';
|
||||||
|
import 'package:fluffychat/utils/event_extension.dart';
|
||||||
import 'package:fluffychat/utils/string_color.dart';
|
import 'package:fluffychat/utils/string_color.dart';
|
||||||
import 'package:fluffychat/views/image_viewer.dart';
|
import 'package:fluffychat/views/image_viewer.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
@ -71,72 +72,71 @@ class Message extends StatelessWidget {
|
||||||
margin: BubbleEdges.symmetric(horizontal: 4),
|
margin: BubbleEdges.symmetric(horizontal: 4),
|
||||||
color: color,
|
color: color,
|
||||||
nip: nip,
|
nip: nip,
|
||||||
child: Column(
|
child: Stack(
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Row(
|
Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(
|
if (event.isReply)
|
||||||
ownMessage
|
FutureBuilder<Event>(
|
||||||
? I18n.of(context).you
|
future: event.getReplyEvent(timeline),
|
||||||
: event.sender.calcDisplayname(),
|
builder: (BuildContext context, snapshot) {
|
||||||
style: TextStyle(
|
final Event replyEvent = snapshot.hasData
|
||||||
color: ownMessage
|
? snapshot.data
|
||||||
? textColor
|
: Event(
|
||||||
: event.sender.calcDisplayname().color,
|
eventId: event.content['m.relates_to']
|
||||||
fontWeight: FontWeight.bold,
|
['m.in_reply_to']['event_id'],
|
||||||
|
content: {"msgtype": "m.text", "body": "..."},
|
||||||
|
senderId: event.senderId,
|
||||||
|
typeKey: "m.room.message",
|
||||||
|
room: event.room,
|
||||||
|
roomId: event.roomId,
|
||||||
|
status: 1,
|
||||||
|
time: DateTime.now(),
|
||||||
|
);
|
||||||
|
return Container(
|
||||||
|
margin: EdgeInsets.symmetric(vertical: 4.0),
|
||||||
|
child:
|
||||||
|
ReplyContent(replyEvent, lightText: ownMessage),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
|
MessageContent(
|
||||||
|
event,
|
||||||
|
textColor: textColor,
|
||||||
),
|
),
|
||||||
SizedBox(width: 4),
|
if (event.type == EventTypes.Encrypted &&
|
||||||
Text(
|
event.messageType == MessageTypes.BadEncrypted &&
|
||||||
event.time.localizedTime(context),
|
event.content["body"] == DecryptError.UNKNOWN_SESSION)
|
||||||
style: TextStyle(
|
RaisedButton(
|
||||||
color: textColor.withAlpha(180),
|
color: color.withAlpha(100),
|
||||||
|
child: Text(
|
||||||
|
I18n.of(context).requestPermission,
|
||||||
|
style: TextStyle(color: textColor),
|
||||||
|
),
|
||||||
|
onPressed: () => Matrix.of(context)
|
||||||
|
.tryRequestWithLoadingDialog(event.requestKey()),
|
||||||
),
|
),
|
||||||
|
SizedBox(height: 4),
|
||||||
|
_MetaRow(
|
||||||
|
event,
|
||||||
|
ownMessage,
|
||||||
|
textColor,
|
||||||
|
invisible: true,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (event.isReply)
|
Positioned(
|
||||||
FutureBuilder<Event>(
|
bottom: 0,
|
||||||
future: event.getReplyEvent(timeline),
|
right: ownMessage ? 0 : null,
|
||||||
builder: (BuildContext context, snapshot) {
|
left: !ownMessage ? 0 : null,
|
||||||
final Event replyEvent = snapshot.hasData
|
child: _MetaRow(
|
||||||
? snapshot.data
|
event,
|
||||||
: Event(
|
ownMessage,
|
||||||
eventId: event.content['m.relates_to']
|
textColor,
|
||||||
['m.in_reply_to']['event_id'],
|
|
||||||
content: {"msgtype": "m.text", "body": "..."},
|
|
||||||
senderId: event.senderId,
|
|
||||||
typeKey: "m.room.message",
|
|
||||||
room: event.room,
|
|
||||||
roomId: event.roomId,
|
|
||||||
status: 1,
|
|
||||||
time: DateTime.now(),
|
|
||||||
);
|
|
||||||
return Container(
|
|
||||||
margin: EdgeInsets.symmetric(vertical: 4.0),
|
|
||||||
child: ReplyContent(replyEvent, lightText: ownMessage),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
MessageContent(
|
|
||||||
event,
|
|
||||||
textColor: textColor,
|
|
||||||
),
|
),
|
||||||
if (event.type == EventTypes.Encrypted &&
|
|
||||||
event.messageType == MessageTypes.BadEncrypted &&
|
|
||||||
event.content["body"] == DecryptError.UNKNOWN_SESSION)
|
|
||||||
RaisedButton(
|
|
||||||
color: color.withAlpha(100),
|
|
||||||
child: Text(
|
|
||||||
I18n.of(context).requestPermission,
|
|
||||||
style: TextStyle(color: textColor),
|
|
||||||
),
|
|
||||||
onPressed: () => Matrix.of(context)
|
|
||||||
.tryRequestWithLoadingDialog(event.requestKey()),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -179,3 +179,50 @@ class Message extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _MetaRow extends StatelessWidget {
|
||||||
|
final Event event;
|
||||||
|
final bool invisible;
|
||||||
|
final bool ownMessage;
|
||||||
|
final Color color;
|
||||||
|
|
||||||
|
const _MetaRow(this.event, this.ownMessage, this.color,
|
||||||
|
{this.invisible = false, Key key})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final String displayname = event.sender.calcDisplayname();
|
||||||
|
final bool showDisplayname =
|
||||||
|
!ownMessage && event.senderId != event.room.directChatMatrixID;
|
||||||
|
return Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: <Widget>[
|
||||||
|
if (showDisplayname)
|
||||||
|
Text(
|
||||||
|
displayname,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: invisible ? Colors.transparent : displayname.color,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (showDisplayname) SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
event.time.localizedTime(context),
|
||||||
|
style: TextStyle(
|
||||||
|
color: invisible ? Colors.transparent : color,
|
||||||
|
fontSize: 11,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (ownMessage) SizedBox(width: 2),
|
||||||
|
if (ownMessage)
|
||||||
|
Icon(
|
||||||
|
event.statusIcon,
|
||||||
|
size: 12,
|
||||||
|
color: invisible ? Colors.transparent : color,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,18 +17,16 @@ class StateMessage extends StatelessWidget {
|
||||||
right: 8.0,
|
right: 8.0,
|
||||||
bottom: 8.0,
|
bottom: 8.0,
|
||||||
),
|
),
|
||||||
child: Opacity(
|
child: Bubble(
|
||||||
opacity: 0.5,
|
elevation: 0,
|
||||||
child: Bubble(
|
color: Theme.of(context).backgroundColor.withOpacity(0.5),
|
||||||
elevation: 0,
|
alignment: Alignment.center,
|
||||||
color: Colors.black,
|
child: LinkText(
|
||||||
alignment: Alignment.center,
|
text: event.getLocalizedBody(context),
|
||||||
child: LinkText(
|
textAlign: TextAlign.center,
|
||||||
text: event.getLocalizedBody(context),
|
textStyle: TextStyle(
|
||||||
textStyle: TextStyle(
|
color: Theme.of(context).primaryColor,
|
||||||
color: Colors.white,
|
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
||||||
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -245,4 +245,19 @@ extension LocalizedBody on Event {
|
||||||
|
|
||||||
return localizedBody;
|
return localizedBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IconData get statusIcon {
|
||||||
|
switch (this.status) {
|
||||||
|
case -1:
|
||||||
|
return Icons.error_outline;
|
||||||
|
case 0:
|
||||||
|
return Icons.timer;
|
||||||
|
case 1:
|
||||||
|
return Icons.done;
|
||||||
|
case 2:
|
||||||
|
return Icons.done_all;
|
||||||
|
default:
|
||||||
|
return Icons.done;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
10
pubspec.lock
10
pubspec.lock
|
@ -124,8 +124,8 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: "7c7f2a3dd80b4c40c1e3c106f75a0af985a2221b"
|
ref: eb84c2a0856af99527f00697cbed4eb67a47887d
|
||||||
resolved-ref: "7c7f2a3dd80b4c40c1e3c106f75a0af985a2221b"
|
resolved-ref: eb84c2a0856af99527f00697cbed4eb67a47887d
|
||||||
url: "https://gitlab.com/famedly/famedlysdk.git"
|
url: "https://gitlab.com/famedly/famedlysdk.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.1"
|
version: "0.0.1"
|
||||||
|
@ -274,7 +274,7 @@ packages:
|
||||||
name: intl
|
name: intl
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.16.1"
|
version: "0.16.0"
|
||||||
intl_translation:
|
intl_translation:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -377,8 +377,8 @@ packages:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: "307dc133867eb5bf80d4f5c7412e58621dfca3cf"
|
ref: bbc7ce10a52be5d5c10d2eb6c3591aade71356e2
|
||||||
resolved-ref: "307dc133867eb5bf80d4f5c7412e58621dfca3cf"
|
resolved-ref: bbc7ce10a52be5d5c10d2eb6c3591aade71356e2
|
||||||
url: "https://gitlab.com/famedly/libraries/dart-olm.git"
|
url: "https://gitlab.com/famedly/libraries/dart-olm.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
|
Loading…
Reference in a new issue