2023-05-15 09:45:41 -04:00
|
|
|
import 'package:contacts_plus_plus/client_holder.dart';
|
2023-05-06 13:24:28 -04:00
|
|
|
import 'package:contacts_plus_plus/models/message.dart';
|
2023-05-07 06:53:19 -04:00
|
|
|
import 'package:contacts_plus_plus/widgets/messages/message_asset.dart';
|
2023-05-06 13:24:28 -04:00
|
|
|
import 'package:contacts_plus_plus/widgets/messages/message_audio_player.dart';
|
|
|
|
import 'package:contacts_plus_plus/widgets/messages/message_session_invite.dart';
|
2023-05-15 09:45:41 -04:00
|
|
|
import 'package:contacts_plus_plus/widgets/messages/message_text.dart';
|
2023-05-06 13:24:28 -04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2023-05-15 09:45:41 -04:00
|
|
|
class MessageBubble extends StatelessWidget {
|
|
|
|
const MessageBubble({required this.message, super.key});
|
2023-05-06 13:24:28 -04:00
|
|
|
|
|
|
|
final Message message;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-05-15 09:45:41 -04:00
|
|
|
final bool mine = message.senderId == ClientHolder.of(context).apiClient.userId;
|
|
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
final foregroundColor = mine ? colorScheme.onPrimaryContainer : colorScheme.onSurfaceVariant;
|
|
|
|
final backgroundColor = mine ? colorScheme.primaryContainer : colorScheme.surfaceVariant;
|
|
|
|
return Padding(
|
|
|
|
padding: EdgeInsets.only(left: mine ? 32 : 12, bottom: 16, right: mine ? 12 : 32),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: mine ? MainAxisAlignment.end : MainAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Material(
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
color: backgroundColor,
|
2023-05-16 04:51:55 -04:00
|
|
|
textStyle: Theme.of(context).textTheme.bodySmall?.copyWith(color: foregroundColor),
|
2023-05-15 09:45:41 -04:00
|
|
|
child: Container(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
|
|
|
child: switch (message.type) {
|
|
|
|
MessageType.sessionInvite =>
|
|
|
|
MessageSessionInvite(message: message, foregroundColor: foregroundColor,),
|
|
|
|
MessageType.object => MessageAsset(message: message, foregroundColor: foregroundColor,),
|
|
|
|
MessageType.sound => MessageAudioPlayer(message: message, foregroundColor: foregroundColor,),
|
|
|
|
MessageType.unknown || MessageType.text => MessageText(message: message, foregroundColor: foregroundColor,)
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2023-05-06 13:24:28 -04:00
|
|
|
}
|
|
|
|
}
|