forked from eatvio/eatvio_app
feat(chat): add image gallery and file loading, request for websocket
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class ChatBubbleWidget extends StatelessWidget {
|
||||
const ChatBubbleWidget({
|
||||
super.key,
|
||||
required this.text,
|
||||
required this.isCurrentUser,
|
||||
this.mediaData,
|
||||
});
|
||||
|
||||
final String text;
|
||||
final bool isCurrentUser;
|
||||
final List<dynamic>? mediaData;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -18,16 +24,80 @@ class ChatBubbleWidget extends StatelessWidget {
|
||||
alignment: isCurrentUser ? Alignment.centerRight : Alignment.centerLeft,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: isCurrentUser ? Colors.blue : Colors.grey[300],
|
||||
color: isCurrentUser ? Color(0xFFF6FAFF) : Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: isCurrentUser ? Colors.white : Colors.black87,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
if (mediaData != null)
|
||||
ListView.separated(
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (context, index) {
|
||||
if (!mediaData![index].toString().contains('.png') &&
|
||||
!mediaData![index].toString().contains('.jpg') &&
|
||||
!mediaData![index].toString().contains('.jpeg')) {
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
horizontalTitleGap: 8,
|
||||
onTap: () async {
|
||||
if (!await launchUrl(Uri.parse(dotenv.env['STORAGE_URL']! + mediaData![index].toString()))) {
|
||||
throw Exception('Could not launch ${mediaData![index].toString()}');
|
||||
}
|
||||
},
|
||||
leading: Icon(
|
||||
Icons.file_copy_outlined,
|
||||
color: Color(0xFF2F80ED),
|
||||
),
|
||||
trailing: Icon(
|
||||
Icons.download_outlined,
|
||||
color: Color(0xFF2F80ED),
|
||||
),
|
||||
title: Text(
|
||||
mediaData![index].toString().replaceAll('chat_files/', ''),
|
||||
maxLines: 2,
|
||||
style: TextStyle(
|
||||
color: Color(0xFF323F4B),
|
||||
fontSize: 12,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
GoRouter.of(context).pushNamed(
|
||||
'photoViewScreen',
|
||||
extra: mediaData!.map((e) => dotenv.env['STORAGE_URL']! + e.toString()).toList(),
|
||||
pathParameters: {
|
||||
'index': index.toString(),
|
||||
},
|
||||
);
|
||||
},
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: dotenv.env['STORAGE_URL']! + '${mediaData![index]}',
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) {
|
||||
return SizedBox(height: 8);
|
||||
},
|
||||
itemCount: mediaData!.length,
|
||||
),
|
||||
if (mediaData!.length > 0 && text.isNotEmpty) SizedBox(height: 8),
|
||||
if (text.isNotEmpty)
|
||||
Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: Color(0xFF323F4B),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user