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

74 lines
2.0 KiB
Dart
Raw Normal View History

2020-05-03 11:56:53 +02:00
import 'package:flutter/material.dart';
2021-10-26 18:50:34 +02:00
import 'package:matrix/matrix.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/event_extension.dart';
2020-05-03 11:56:53 +02:00
class MessageDownloadContent extends StatelessWidget {
final Event event;
final Color textColor;
2022-01-02 10:12:03 +01:00
const MessageDownloadContent(this.event, this.textColor, {Key? key})
2020-05-03 11:56:53 +02:00
: super(key: key);
@override
Widget build(BuildContext context) {
2022-01-02 10:12:03 +01: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>[
Row(
children: [
Icon(
Icons.file_download_outlined,
color: textColor,
2022-01-02 10:12:03 +01:00
),
const SizedBox(width: 8),
Expanded(
child: Text(
filename,
maxLines: 1,
style: TextStyle(
color: textColor,
2022-01-02 10:12:03 +01:00
fontWeight: FontWeight.bold,
),
),
),
],
),
const Divider(),
Row(
children: [
Text(
filetype,
style: TextStyle(
color: textColor.withAlpha(150),
2022-01-02 10:12:03 +01:00
),
),
const Spacer(),
if (sizeString != null)
Text(
sizeString,
style: TextStyle(
color: textColor.withAlpha(150),
2022-01-02 10:12:03 +01:00
),
),
],
2021-10-14 18:09:30 +02:00
),
2022-01-02 10:12:03 +01:00
],
),
2020-05-03 11:56:53 +02:00
);
}
}