mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-02 17:29:34 +01:00
feat: Nicer file event design
This commit is contained in:
parent
e0d4798fd8
commit
2089305639
@ -1,42 +1,75 @@
|
|||||||
|
//@dart=2.12
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/event_extension.dart';
|
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/event_extension.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
|
||||||
|
|
||||||
class MessageDownloadContent extends StatelessWidget {
|
class MessageDownloadContent extends StatelessWidget {
|
||||||
final Event event;
|
final Event event;
|
||||||
final Color textColor;
|
final Color textColor;
|
||||||
|
|
||||||
const MessageDownloadContent(this.event, this.textColor, {Key key})
|
const MessageDownloadContent(this.event, this.textColor, {Key? key})
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final String filename = event.content.containsKey('filename')
|
final filename = event.content.tryGet<String>('filename') ?? event.body;
|
||||||
? event.content['filename']
|
final filetype = (filename.contains('.')
|
||||||
: event.body;
|
? filename.split('.').last.toUpperCase()
|
||||||
return Column(
|
: 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,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
TextButton.icon(
|
Row(
|
||||||
onPressed: () => event.saveFile(context),
|
children: [
|
||||||
icon: const Icon(Icons.download_outlined),
|
Icon(
|
||||||
label: Text(filename),
|
Icons.file_download_outlined,
|
||||||
style: event.senderId == Matrix.of(context).client.userID
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
? TextButton.styleFrom(primary: textColor)
|
|
||||||
: null,
|
|
||||||
),
|
),
|
||||||
if (event.sizeString != null)
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
filename,
|
||||||
|
maxLines: 1,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
Text(
|
Text(
|
||||||
event.sizeString,
|
filetype,
|
||||||
|
style: TextStyle(
|
||||||
|
color: textColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Spacer(),
|
||||||
|
if (sizeString != null)
|
||||||
|
Text(
|
||||||
|
sizeString,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: textColor,
|
color: textColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user