forked from eatvio/eatvio_app
115 lines
4.8 KiB
Dart
115 lines
4.8 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:dismissible_page/dismissible_page.dart';
|
|
import 'package:eatvio_app/features/chat/presentation/pages/photo_view_screen.dart';
|
|
import 'package:eatvio_app/theme/app_decoration.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_dotenv/flutter_dotenv.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) {
|
|
return Padding(
|
|
padding: EdgeInsets.fromLTRB(isCurrentUser ? 64 : 16, 4, isCurrentUser ? 16 : 64, 4),
|
|
child: Align(
|
|
alignment: isCurrentUser ? Alignment.centerRight : Alignment.centerLeft,
|
|
child: DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
color: isCurrentUser ? Color(0xFFF6FAFF) : Colors.white,
|
|
borderRadius: BorderRadiusStyle.circleBorder17,
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12),
|
|
child: Column(
|
|
children: [
|
|
if (mediaData != null)
|
|
CustomScrollView(
|
|
shrinkWrap: true,
|
|
physics: NeverScrollableScrollPhysics(),
|
|
slivers: [
|
|
SliverList.separated(
|
|
itemBuilder: (BuildContext context, int 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: () {
|
|
context.pushTransparentRoute(
|
|
PhotoViewScreen(
|
|
imageUrls: mediaData!.map((e) => dotenv.env['STORAGE_URL']! + e.toString()).toList(),
|
|
index: index,
|
|
),
|
|
);
|
|
},
|
|
child: Hero(
|
|
tag: dotenv.env['STORAGE_URL']! + '${mediaData![index]}',
|
|
transitionOnUserGestures: true,
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadiusStyle.roundedBorder8,
|
|
child: CachedNetworkImage(
|
|
imageUrl: dotenv.env['STORAGE_URL']! + '${mediaData![index]}',
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
separatorBuilder: (BuildContext context, int index) => const 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),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|