fix: Send file

This commit is contained in:
Christian Pauly 2021-01-18 10:43:00 +01:00
parent 913f3cfa70
commit fde2f8b2a8
5 changed files with 25 additions and 22 deletions

View File

@ -10,8 +10,14 @@ import '../../utils/resize_image.dart';
class SendFileDialog extends StatefulWidget {
final Room room;
final MatrixFile file;
final L10n l10n;
const SendFileDialog({this.room, this.file, Key key}) : super(key: key);
const SendFileDialog({
this.room,
@required this.l10n,
this.file,
Key key,
}) : super(key: key);
@override
_SendFileDialogState createState() => _SendFileDialogState();
@ -34,13 +40,13 @@ class _SendFileDialogState extends State<SendFileDialog> {
@override
Widget build(BuildContext context) {
var sendStr = L10n.of(context).sendFile;
var sendStr = widget.l10n.sendFile;
if (widget.file is MatrixImageFile) {
sendStr = L10n.of(context).sendImage;
sendStr = widget.l10n.sendImage;
} else if (widget.file is MatrixAudioFile) {
sendStr = L10n.of(context).sendAudio;
sendStr = widget.l10n.sendAudio;
} else if (widget.file is MatrixVideoFile) {
sendStr = L10n.of(context).sendVideo;
sendStr = widget.l10n.sendVideo;
}
Widget contentWidget;
if (widget.file is MatrixImageFile) {
@ -60,8 +66,8 @@ class _SendFileDialogState extends State<SendFileDialog> {
),
InkWell(
onTap: () => setState(() => origImage = !origImage),
child: Text(L10n.of(context).sendOriginal +
' (${widget.file.sizeString})'),
child: Text(
widget.l10n.sendOriginal + ' (${widget.file.sizeString})'),
),
],
)
@ -74,14 +80,14 @@ class _SendFileDialogState extends State<SendFileDialog> {
content: contentWidget,
actions: <Widget>[
FlatButton(
child: Text(L10n.of(context).cancel),
child: Text(widget.l10n.cancel),
onPressed: () {
// just close the dialog
Navigator.of(context).pop();
},
),
FlatButton(
child: Text(L10n.of(context).send),
child: Text(widget.l10n.send),
onPressed: _isSending
? null
: () async {

View File

@ -94,6 +94,7 @@ class ChatListItem extends StatelessWidget {
builder: (c) => SendFileDialog(
file: Matrix.of(context).shareContent['file'],
room: room,
l10n: L10n.of(context),
));
} else {
unawaited(room.sendEvent(Matrix.of(context).shareContent));

View File

@ -214,12 +214,13 @@ class _ChatState extends State<Chat> {
if (result == null) return;
await showDialog(
context: context,
builder: (context) => SendFileDialog(
builder: (c) => SendFileDialog(
file: MatrixFile(
bytes: result.toUint8List(),
name: result.fileName,
).detectFileType,
room: room,
l10n: L10n.of(context),
),
);
}
@ -230,12 +231,13 @@ class _ChatState extends State<Chat> {
if (result == null) return;
await showDialog(
context: context,
builder: (context) => SendFileDialog(
builder: (c) => SendFileDialog(
file: MatrixImageFile(
bytes: result.toUint8List(),
name: result.fileName,
),
room: room,
l10n: L10n.of(context),
),
);
}
@ -246,12 +248,13 @@ class _ChatState extends State<Chat> {
final bytes = await file.readAsBytes();
await showDialog(
context: context,
builder: (context) => SendFileDialog(
builder: (c) => SendFileDialog(
file: MatrixImageFile(
bytes: bytes,
name: file.path,
),
room: room,
l10n: L10n.of(context),
),
);
}

View File

@ -247,21 +247,14 @@ packages:
name: file_picker
url: "https://pub.dartlang.org"
source: hosted
version: "1.13.3"
version: "2.1.5+1"
file_picker_cross:
dependency: "direct main"
description:
name: file_picker_cross
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.2"
file_picker_platform_interface:
dependency: transitive
description:
name: file_picker_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "4.2.7"
firebase:
dependency: transitive
description:

View File

@ -16,7 +16,7 @@ dependencies:
ref: main
localstorage: ^3.0.6+9
file_picker_cross: 4.2.2
file_picker_cross: ^4.2.7
image_picker: ^0.6.7+21
url_launcher: ^5.7.10
cached_network_image: ^2.5.0