2023-05-07 06:53:19 -04:00
|
|
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2023-10-03 13:00:59 -04:00
|
|
|
import 'package:recon/auxiliary.dart';
|
|
|
|
import 'package:recon/models/photo_asset.dart';
|
|
|
|
import 'package:recon/models/message.dart';
|
|
|
|
import 'package:recon/string_formatter.dart';
|
|
|
|
import 'package:recon/widgets/formatted_text.dart';
|
|
|
|
import 'package:recon/widgets/messages/message_state_indicator.dart';
|
2023-05-07 06:53:19 -04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:photo_view/photo_view.dart';
|
|
|
|
|
|
|
|
class MessageAsset extends StatelessWidget {
|
2023-05-15 09:45:41 -04:00
|
|
|
const MessageAsset({required this.message, this.foregroundColor, super.key});
|
2023-05-07 06:53:19 -04:00
|
|
|
|
|
|
|
final Message message;
|
2023-05-15 09:45:41 -04:00
|
|
|
final Color? foregroundColor;
|
2023-05-07 06:53:19 -04:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final content = jsonDecode(message.content);
|
2023-05-12 12:31:05 -04:00
|
|
|
final formattedName = FormatNode.fromText(content["name"]);
|
2023-05-07 06:53:19 -04:00
|
|
|
return Container(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 300),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2023-05-28 10:38:59 -04:00
|
|
|
SizedBox(
|
|
|
|
height: 256,
|
|
|
|
width: double.infinity,
|
|
|
|
child: CachedNetworkImage(
|
2023-09-29 03:51:46 -04:00
|
|
|
imageUrl: Aux.resdbToHttp(content["thumbnailUri"]),
|
2023-05-28 10:38:59 -04:00
|
|
|
imageBuilder: (context, image) {
|
|
|
|
return InkWell(
|
|
|
|
onTap: () async {
|
|
|
|
PhotoAsset? photoAsset;
|
|
|
|
try {
|
|
|
|
photoAsset = PhotoAsset.fromTags((content["tags"] as List).map((e) => "$e").toList());
|
|
|
|
} catch (_) {}
|
|
|
|
await Navigator.push(
|
|
|
|
context, MaterialPageRoute(builder: (context) =>
|
|
|
|
PhotoView(
|
|
|
|
minScale: PhotoViewComputedScale.contained,
|
|
|
|
imageProvider: photoAsset == null
|
|
|
|
? image
|
2023-09-29 03:51:46 -04:00
|
|
|
: CachedNetworkImageProvider(Aux.resdbToHttp(photoAsset.imageUri)),
|
2023-05-28 10:38:59 -04:00
|
|
|
heroAttributes: PhotoViewHeroAttributes(tag: message.id),
|
|
|
|
),
|
|
|
|
),);
|
|
|
|
},
|
|
|
|
child: Hero(
|
|
|
|
tag: message.id,
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
child: Image(image: image, fit: BoxFit.cover,),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
errorWidget: (context, url, error) => const Icon(Icons.broken_image, size: 64,),
|
|
|
|
placeholder: (context, uri) => const Center(child: CircularProgressIndicator()),
|
|
|
|
),
|
2023-05-07 06:53:19 -04:00
|
|
|
),
|
|
|
|
const SizedBox(height: 8,),
|
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2023-05-12 12:31:05 -04:00
|
|
|
Expanded(
|
2023-05-15 09:45:41 -04:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
|
|
|
child: FormattedText(
|
|
|
|
formattedName,
|
|
|
|
maxLines: null,
|
|
|
|
style: Theme
|
|
|
|
.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodySmall
|
|
|
|
?.copyWith(color: foregroundColor),
|
|
|
|
),
|
2023-05-12 12:31:05 -04:00
|
|
|
),
|
|
|
|
),
|
2023-05-15 09:45:41 -04:00
|
|
|
MessageStateIndicator(message: message, foregroundColor: foregroundColor,),
|
2023-05-07 06:53:19 -04:00
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|