mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
Fix files background color
This commit is contained in:
parent
75a80b1018
commit
0458d5431c
@ -5,6 +5,7 @@ import 'package:comunic/helpers/events_helper.dart';
|
|||||||
import 'package:comunic/helpers/users_helper.dart';
|
import 'package:comunic/helpers/users_helper.dart';
|
||||||
import 'package:comunic/lists/conversation_messages_list.dart';
|
import 'package:comunic/lists/conversation_messages_list.dart';
|
||||||
import 'package:comunic/lists/users_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/conversation_message.dart';
|
||||||
import 'package:comunic/models/new_conversation_message.dart';
|
import 'package:comunic/models/new_conversation_message.dart';
|
||||||
import 'package:comunic/ui/tiles/conversation_message_tile.dart';
|
import 'package:comunic/ui/tiles/conversation_message_tile.dart';
|
||||||
@ -41,6 +42,7 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
|
|||||||
final UsersHelper _usersHelper = UsersHelper();
|
final UsersHelper _usersHelper = UsersHelper();
|
||||||
|
|
||||||
// Class members
|
// Class members
|
||||||
|
Conversation _conversation;
|
||||||
ConversationMessagesList _messages;
|
ConversationMessagesList _messages;
|
||||||
UsersList _usersInfo = UsersList();
|
UsersList _usersInfo = UsersList();
|
||||||
ErrorLevel _error = ErrorLevel.NONE;
|
ErrorLevel _error = ErrorLevel.NONE;
|
||||||
@ -78,6 +80,9 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
|
|||||||
Future<void> _init() async {
|
Future<void> _init() async {
|
||||||
_scrollController = ScrollWatcher(onReachBottom: _loadOlderMessages);
|
_scrollController = ScrollWatcher(onReachBottom: _loadOlderMessages);
|
||||||
|
|
||||||
|
_conversation =
|
||||||
|
await ConversationsHelper().getSingle(widget.conversationID);
|
||||||
|
|
||||||
// Fetch latest messages
|
// Fetch latest messages
|
||||||
await _loadMessages(false);
|
await _loadMessages(false);
|
||||||
await _loadMessages(true);
|
await _loadMessages(true);
|
||||||
@ -321,6 +326,7 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
|
|||||||
users: _usersInfo,
|
users: _usersInfo,
|
||||||
)
|
)
|
||||||
: ConversationMessageTile(
|
: ConversationMessageTile(
|
||||||
|
conversation: _conversation,
|
||||||
message: _messages.elementAt(i),
|
message: _messages.elementAt(i),
|
||||||
userInfo: _usersInfo.getUser(_messages[i].userID),
|
userInfo: _usersInfo.getUser(_messages[i].userID),
|
||||||
isLastMessage: _isLastMessage(i),
|
isLastMessage: _isLastMessage(i),
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:comunic/models/conversation.dart';
|
||||||
import 'package:comunic/models/conversation_message.dart';
|
import 'package:comunic/models/conversation_message.dart';
|
||||||
import 'package:comunic/models/user.dart';
|
import 'package:comunic/models/user.dart';
|
||||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||||
@ -18,6 +19,7 @@ typedef OnRequestMessageUpdate = void Function(ConversationMessage);
|
|||||||
typedef OnRequestMessageDelete = void Function(ConversationMessage);
|
typedef OnRequestMessageDelete = void Function(ConversationMessage);
|
||||||
|
|
||||||
class ConversationMessageTile extends StatelessWidget {
|
class ConversationMessageTile extends StatelessWidget {
|
||||||
|
final Conversation conversation;
|
||||||
final ConversationMessage message;
|
final ConversationMessage message;
|
||||||
final User userInfo;
|
final User userInfo;
|
||||||
final bool isLastMessage;
|
final bool isLastMessage;
|
||||||
@ -27,6 +29,7 @@ class ConversationMessageTile extends StatelessWidget {
|
|||||||
|
|
||||||
const ConversationMessageTile({
|
const ConversationMessageTile({
|
||||||
Key key,
|
Key key,
|
||||||
|
@required this.conversation,
|
||||||
@required this.message,
|
@required this.message,
|
||||||
@required this.userInfo,
|
@required this.userInfo,
|
||||||
@required this.isLastMessage,
|
@required this.isLastMessage,
|
||||||
@ -41,6 +44,12 @@ class ConversationMessageTile extends StatelessWidget {
|
|||||||
assert(onRequestMessageDelete != null),
|
assert(onRequestMessageDelete != null),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
|
Color get backgroundColor => message.isOwner
|
||||||
|
? conversation.color ?? Colors.blueAccent
|
||||||
|
: darkTheme()
|
||||||
|
? Colors.white12
|
||||||
|
: Colors.black12;
|
||||||
|
|
||||||
/// Build account image
|
/// Build account image
|
||||||
Widget _buildAccountImage(BuildContext context) {
|
Widget _buildAccountImage(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
@ -74,6 +83,7 @@ class ConversationMessageTile extends StatelessWidget {
|
|||||||
Widget _buildMessageFile(BuildContext context) => ConversationFileWidget(
|
Widget _buildMessageFile(BuildContext context) => ConversationFileWidget(
|
||||||
messageID: message.id,
|
messageID: message.id,
|
||||||
file: message.file,
|
file: message.file,
|
||||||
|
defaultBackgroundColor: backgroundColor,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Build message date
|
/// Build message date
|
||||||
@ -127,7 +137,7 @@ class ConversationMessageTile extends StatelessWidget {
|
|||||||
padding: EdgeInsets.fromLTRB(
|
padding: EdgeInsets.fromLTRB(
|
||||||
15.0, 10.0, 15.0, 10.0),
|
15.0, 10.0, 15.0, 10.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.blueAccent,
|
color: backgroundColor,
|
||||||
borderRadius: BorderRadius.circular(8.0),
|
borderRadius: BorderRadius.circular(8.0),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -204,9 +214,7 @@ class ConversationMessageTile extends StatelessWidget {
|
|||||||
padding:
|
padding:
|
||||||
EdgeInsets.fromLTRB(15.0, 10.0, 15.0, 10.0),
|
EdgeInsets.fromLTRB(15.0, 10.0, 15.0, 10.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: darkTheme()
|
color: backgroundColor,
|
||||||
? Colors.white12
|
|
||||||
: Colors.black12,
|
|
||||||
borderRadius: BorderRadius.circular(8.0),
|
borderRadius: BorderRadius.circular(8.0),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -11,9 +11,11 @@ const _AreaSize = 150.0;
|
|||||||
class ConversationFileWidget extends StatefulWidget {
|
class ConversationFileWidget extends StatefulWidget {
|
||||||
final int messageID;
|
final int messageID;
|
||||||
final ConversationMessageFile file;
|
final ConversationMessageFile file;
|
||||||
|
final Color defaultBackgroundColor;
|
||||||
|
|
||||||
const ConversationFileWidget({
|
const ConversationFileWidget({
|
||||||
Key key,
|
Key key,
|
||||||
|
@required this.defaultBackgroundColor,
|
||||||
@required this.messageID,
|
@required this.messageID,
|
||||||
@required this.file,
|
@required this.file,
|
||||||
}) : assert(messageID != null),
|
}) : assert(messageID != null),
|
||||||
@ -28,8 +30,11 @@ class _ConversationFileWidgetState extends State<ConversationFileWidget> {
|
|||||||
ConversationMessageFile get file => widget.file;
|
ConversationMessageFile get file => widget.file;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) =>
|
Widget build(BuildContext context) => Container(
|
||||||
Container(width: _AreaSize, height: _AreaSize, child: _buildContent());
|
width: _AreaSize,
|
||||||
|
height: _AreaSize,
|
||||||
|
child: _buildContent(),
|
||||||
|
);
|
||||||
|
|
||||||
Widget _buildContent() {
|
Widget _buildContent() {
|
||||||
switch (file.fileType) {
|
switch (file.fileType) {
|
||||||
@ -45,20 +50,23 @@ class _ConversationFileWidgetState extends State<ConversationFileWidget> {
|
|||||||
|
|
||||||
// The file is not downloadable, we open it in the browser
|
// The file is not downloadable, we open it in the browser
|
||||||
default:
|
default:
|
||||||
return Center(
|
return Container(
|
||||||
child: MaterialButton(
|
color: widget.defaultBackgroundColor,
|
||||||
child: Column(
|
child: Center(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
child: MaterialButton(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
child: Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
Spacer(flex: 2),
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
Icon(file.icon, color: Colors.white),
|
children: [
|
||||||
Spacer(),
|
Spacer(flex: 2),
|
||||||
Text(file.name, textAlign: TextAlign.center),
|
Icon(file.icon, color: Colors.white),
|
||||||
Spacer(flex: 2),
|
Spacer(),
|
||||||
],
|
Text(file.name, textAlign: TextAlign.center),
|
||||||
|
Spacer(flex: 2),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onPressed: () => launch(file.url),
|
||||||
),
|
),
|
||||||
onPressed: () => launch(file.url),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user