OpenContacts/lib/widgets/messages/message_asset.dart

82 lines
3 KiB
Dart
Raw Normal View History

2023-05-07 06:53:19 -04:00
import 'dart:convert';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:contacts_plus_plus/auxiliary.dart';
import 'package:contacts_plus_plus/models/photo_asset.dart';
import 'package:contacts_plus_plus/models/message.dart';
2023-05-12 12:31:05 -04:00
import 'package:contacts_plus_plus/string_formatter.dart';
import 'package:contacts_plus_plus/widgets/formatted_text.dart';
2023-05-07 06:53:19 -04:00
import 'package:contacts_plus_plus/widgets/messages/message_state_indicator.dart';
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
class MessageAsset extends StatelessWidget {
const MessageAsset({required this.message, this.foregroundColor, super.key});
2023-05-07 06:53:19 -04:00
final Message message;
final Color? foregroundColor;
2023-05-07 06:53:19 -04:00
@override
Widget build(BuildContext context) {
final content = jsonDecode(message.content);
PhotoAsset? photoAsset;
try {
photoAsset = PhotoAsset.fromTags((content["tags"] as List).map((e) => "$e").toList());
} catch (_) {}
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: [
CachedNetworkImage(
imageUrl: Aux.neosDbToHttp(content["thumbnailUri"]),
imageBuilder: (context, image) {
return InkWell(
onTap: () async {
await Navigator.push(
context, MaterialPageRoute(builder: (context) =>
PhotoView(
minScale: PhotoViewComputedScale.contained,
imageProvider: photoAsset == null
? image
: CachedNetworkImageProvider(Aux.neosDbToHttp(photoAsset.imageUri)),
heroAttributes: PhotoViewHeroAttributes(tag: message.id),
),
),);
},
child: Hero(
tag: message.id,
child: ClipRRect(borderRadius: BorderRadius.circular(16), child: Image(image: image,)),
),
);
},
placeholder: (context, uri) => const CircularProgressIndicator(),
),
const SizedBox(height: 8,),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
2023-05-12 12:31:05 -04:00
Expanded(
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
),
),
MessageStateIndicator(message: message, foregroundColor: foregroundColor,),
2023-05-07 06:53:19 -04:00
],
),
],
),
);
}
}