1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Fix files background color

This commit is contained in:
Pierre HUBERT 2021-03-11 00:23:11 +01:00
parent 75a80b1018
commit 0458d5431c
3 changed files with 41 additions and 19 deletions

View File

@ -5,6 +5,7 @@ import 'package:comunic/helpers/events_helper.dart';
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/conversation_messages_list.dart';
import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/conversation.dart';
import 'package:comunic/models/conversation_message.dart';
import 'package:comunic/models/new_conversation_message.dart';
import 'package:comunic/ui/tiles/conversation_message_tile.dart';
@ -41,6 +42,7 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
final UsersHelper _usersHelper = UsersHelper();
// Class members
Conversation _conversation;
ConversationMessagesList _messages;
UsersList _usersInfo = UsersList();
ErrorLevel _error = ErrorLevel.NONE;
@ -78,6 +80,9 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
Future<void> _init() async {
_scrollController = ScrollWatcher(onReachBottom: _loadOlderMessages);
_conversation =
await ConversationsHelper().getSingle(widget.conversationID);
// Fetch latest messages
await _loadMessages(false);
await _loadMessages(true);
@ -321,6 +326,7 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
users: _usersInfo,
)
: ConversationMessageTile(
conversation: _conversation,
message: _messages.elementAt(i),
userInfo: _usersInfo.getUser(_messages[i].userID),
isLastMessage: _isLastMessage(i),

View File

@ -1,3 +1,4 @@
import 'package:comunic/models/conversation.dart';
import 'package:comunic/models/conversation_message.dart';
import 'package:comunic/models/user.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
@ -18,6 +19,7 @@ typedef OnRequestMessageUpdate = void Function(ConversationMessage);
typedef OnRequestMessageDelete = void Function(ConversationMessage);
class ConversationMessageTile extends StatelessWidget {
final Conversation conversation;
final ConversationMessage message;
final User userInfo;
final bool isLastMessage;
@ -27,6 +29,7 @@ class ConversationMessageTile extends StatelessWidget {
const ConversationMessageTile({
Key key,
@required this.conversation,
@required this.message,
@required this.userInfo,
@required this.isLastMessage,
@ -41,6 +44,12 @@ class ConversationMessageTile extends StatelessWidget {
assert(onRequestMessageDelete != null),
super(key: key);
Color get backgroundColor => message.isOwner
? conversation.color ?? Colors.blueAccent
: darkTheme()
? Colors.white12
: Colors.black12;
/// Build account image
Widget _buildAccountImage(BuildContext context) {
return Container(
@ -74,6 +83,7 @@ class ConversationMessageTile extends StatelessWidget {
Widget _buildMessageFile(BuildContext context) => ConversationFileWidget(
messageID: message.id,
file: message.file,
defaultBackgroundColor: backgroundColor,
);
/// Build message date
@ -127,7 +137,7 @@ class ConversationMessageTile extends StatelessWidget {
padding: EdgeInsets.fromLTRB(
15.0, 10.0, 15.0, 10.0),
decoration: BoxDecoration(
color: Colors.blueAccent,
color: backgroundColor,
borderRadius: BorderRadius.circular(8.0),
),
),
@ -204,9 +214,7 @@ class ConversationMessageTile extends StatelessWidget {
padding:
EdgeInsets.fromLTRB(15.0, 10.0, 15.0, 10.0),
decoration: BoxDecoration(
color: darkTheme()
? Colors.white12
: Colors.black12,
color: backgroundColor,
borderRadius: BorderRadius.circular(8.0),
),
),

View File

@ -11,9 +11,11 @@ const _AreaSize = 150.0;
class ConversationFileWidget extends StatefulWidget {
final int messageID;
final ConversationMessageFile file;
final Color defaultBackgroundColor;
const ConversationFileWidget({
Key key,
@required this.defaultBackgroundColor,
@required this.messageID,
@required this.file,
}) : assert(messageID != null),
@ -28,8 +30,11 @@ class _ConversationFileWidgetState extends State<ConversationFileWidget> {
ConversationMessageFile get file => widget.file;
@override
Widget build(BuildContext context) =>
Container(width: _AreaSize, height: _AreaSize, child: _buildContent());
Widget build(BuildContext context) => Container(
width: _AreaSize,
height: _AreaSize,
child: _buildContent(),
);
Widget _buildContent() {
switch (file.fileType) {
@ -45,7 +50,9 @@ class _ConversationFileWidgetState extends State<ConversationFileWidget> {
// The file is not downloadable, we open it in the browser
default:
return Center(
return Container(
color: widget.defaultBackgroundColor,
child: Center(
child: MaterialButton(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
@ -60,6 +67,7 @@ class _ConversationFileWidgetState extends State<ConversationFileWidget> {
),
onPressed: () => launch(file.url),
),
),
);
break;
}