2023-08-11 23:02:31 +08:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2023-06-21 17:44:28 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:together_mobile/common/constants.dart';
|
2023-08-11 23:02:31 +08:00
|
|
|
import 'package:together_mobile/models/contact_model.dart';
|
|
|
|
import 'package:together_mobile/models/init_get_it.dart';
|
|
|
|
import 'package:together_mobile/models/user_model.dart';
|
|
|
|
import 'package:together_mobile/request/server.dart';
|
2023-06-21 17:44:28 +08:00
|
|
|
|
|
|
|
class MessageBubble extends StatelessWidget {
|
2023-08-10 19:08:46 +08:00
|
|
|
const MessageBubble({
|
|
|
|
super.key,
|
|
|
|
required this.contactId,
|
|
|
|
required this.senderId,
|
|
|
|
required this.type,
|
|
|
|
required this.dateTime,
|
|
|
|
required this.isShowTime,
|
|
|
|
required this.text,
|
|
|
|
required this.attachments,
|
|
|
|
});
|
|
|
|
|
|
|
|
final String contactId, senderId, type, dateTime, text;
|
|
|
|
final bool isShowTime;
|
|
|
|
final List<String> attachments;
|
2023-06-21 17:44:28 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
vertical: kDefaultPadding / 2,
|
|
|
|
horizontal: kDefaultPadding,
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2023-08-10 19:08:46 +08:00
|
|
|
// message date time
|
|
|
|
if (isShowTime)
|
|
|
|
SizedBox(
|
|
|
|
height: 35.0,
|
|
|
|
child: Text(
|
|
|
|
dateTime,
|
|
|
|
style: const TextStyle(
|
|
|
|
color: kUnActivatedColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-06-21 17:44:28 +08:00
|
|
|
Row(
|
2023-08-10 19:08:46 +08:00
|
|
|
textDirection:
|
|
|
|
senderId == contactId ? TextDirection.ltr : TextDirection.rtl,
|
2023-06-21 17:44:28 +08:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2023-08-11 23:02:31 +08:00
|
|
|
senderId == contactId
|
|
|
|
? getIt
|
|
|
|
.get<ContactAccountProfile>()
|
|
|
|
.friends[contactId]!
|
|
|
|
.avatar
|
|
|
|
.isEmpty
|
|
|
|
? CircleAvatar(
|
|
|
|
child: Image.asset('assets/images/user_2.png'),
|
|
|
|
)
|
|
|
|
: CircleAvatar(
|
|
|
|
backgroundImage: CachedNetworkImageProvider(
|
|
|
|
'$avatarsUrl/${getIt.get<ContactAccountProfile>().friends[contactId]!.avatar}',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: CircleAvatar(
|
|
|
|
backgroundImage: CachedNetworkImageProvider(
|
|
|
|
'$avatarsUrl/${getIt.get<UserProfile>().avatar}',
|
|
|
|
),
|
|
|
|
),
|
2023-06-21 17:44:28 +08:00
|
|
|
const SizedBox(
|
|
|
|
width: 10,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
2023-08-10 19:08:46 +08:00
|
|
|
crossAxisAlignment: senderId == contactId
|
|
|
|
? CrossAxisAlignment.start
|
|
|
|
: CrossAxisAlignment.end,
|
2023-06-21 17:44:28 +08:00
|
|
|
children: [
|
2023-08-10 19:08:46 +08:00
|
|
|
// nickname
|
|
|
|
// used in group chat only
|
|
|
|
// Text('123'),
|
|
|
|
// const SizedBox(
|
|
|
|
// height: 5,
|
|
|
|
// ),
|
|
|
|
|
|
|
|
if (type == 'text/multipart')
|
|
|
|
// message box
|
|
|
|
Container(
|
|
|
|
padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: senderId == contactId
|
|
|
|
? const Color.fromARGB(255, 241, 241, 241)
|
|
|
|
: kPrimaryColor,
|
|
|
|
borderRadius: BorderRadius.circular(10.0),
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
// text message content
|
|
|
|
Text(
|
|
|
|
text,
|
|
|
|
textWidthBasis: TextWidthBasis.longestLine,
|
2023-06-21 17:44:28 +08:00
|
|
|
),
|
2023-08-10 19:08:46 +08:00
|
|
|
const SizedBox(
|
|
|
|
height: 10,
|
2023-06-21 17:44:28 +08:00
|
|
|
),
|
2023-08-10 19:08:46 +08:00
|
|
|
// image content if has
|
|
|
|
if (attachments.isNotEmpty)
|
|
|
|
...List.filled(
|
|
|
|
attachments.length,
|
|
|
|
Container(
|
|
|
|
margin: const EdgeInsets.only(
|
|
|
|
bottom: 10,
|
|
|
|
),
|
|
|
|
constraints: const BoxConstraints(
|
|
|
|
maxHeight: 100,
|
|
|
|
),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(10.0),
|
|
|
|
),
|
|
|
|
child: Image.asset(
|
|
|
|
'assets/images/Logo_dark.png',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-06-21 17:44:28 +08:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {},
|
2023-08-10 19:08:46 +08:00
|
|
|
style: TextButton.styleFrom(
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
),
|
2023-06-21 17:44:28 +08:00
|
|
|
child: const Text('显示信息'),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|