fluffychat/lib/pages/chat/events/message_download_content.dart

80 lines
2.3 KiB
Dart
Raw Normal View History

2020-05-03 09:56:53 +00:00
import 'package:flutter/material.dart';
2021-10-26 16:50:34 +00:00
import 'package:matrix/matrix.dart';
2022-12-30 16:54:01 +00:00
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
2020-05-03 09:56:53 +00:00
class MessageDownloadContent extends StatelessWidget {
final Event event;
final Color textColor;
const MessageDownloadContent(this.event, this.textColor, {super.key});
2020-05-03 09:56:53 +00:00
@override
Widget build(BuildContext context) {
2022-01-02 09:12:03 +00:00
final filename = event.content.tryGet<String>('filename') ?? event.body;
final filetype = (filename.contains('.')
? filename.split('.').last.toUpperCase()
: event.content
.tryGetMap<String, dynamic>('info')
?.tryGet<String>('mimetype')
?.toUpperCase() ??
'UNKNOWN');
final sizeString = event.sizeString;
return InkWell(
onTap: () => event.saveFile(context),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
2022-12-30 11:52:29 +00:00
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
Icon(
Icons.file_download_outlined,
color: textColor,
),
const SizedBox(width: 16),
Flexible(
child: Text(
filename,
maxLines: 1,
style: TextStyle(
color: textColor,
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.ellipsis,
2022-12-30 11:52:29 +00:00
),
2023-08-18 05:24:31 +00:00
),
2022-12-30 11:52:29 +00:00
],
),
2022-01-02 09:12:03 +00:00
),
2022-12-30 09:36:54 +00:00
const Divider(height: 1),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8),
child: Row(
children: [
2022-01-02 09:12:03 +00:00
Text(
2022-12-30 09:36:54 +00:00
filetype,
2022-01-02 09:12:03 +00:00
style: TextStyle(
color: textColor.withAlpha(150),
2022-01-02 09:12:03 +00:00
),
),
2022-12-30 09:36:54 +00:00
const Spacer(),
if (sizeString != null)
Text(
sizeString,
style: TextStyle(
color: textColor.withAlpha(150),
),
),
],
),
2021-10-14 16:09:30 +00:00
),
2022-01-02 09:12:03 +00:00
],
),
2020-05-03 09:56:53 +00:00
);
}
}