2023-10-03 13:00:59 -04:00
|
|
|
import 'package:recon/client_holder.dart';
|
|
|
|
import 'package:recon/models/message.dart';
|
|
|
|
import 'package:recon/widgets/messages/message_asset.dart';
|
|
|
|
import 'package:recon/widgets/messages/message_audio_player.dart';
|
|
|
|
import 'package:recon/widgets/messages/message_session_invite.dart';
|
|
|
|
import 'package:recon/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) {
|
2023-05-18 09:17:05 -04:00
|
|
|
MessageType.sessionInvite => MessageSessionInvite(message: message, foregroundColor: foregroundColor,),
|
2023-05-15 09:45:41 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|