2020-04-02 12:05:32 +00:00
|
|
|
import 'package:bubble/bubble.dart';
|
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluffychat/utils/matrix_file_extension.dart';
|
|
|
|
|
2020-04-28 12:11:56 +00:00
|
|
|
import 'dialogs/simple_dialogs.dart';
|
|
|
|
|
2020-04-02 12:05:32 +00:00
|
|
|
class ImageBubble extends StatefulWidget {
|
|
|
|
final Event event;
|
|
|
|
|
|
|
|
const ImageBubble(this.event, {Key key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_ImageBubbleState createState() => _ImageBubbleState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ImageBubbleState extends State<ImageBubble> {
|
2020-05-13 13:58:59 +00:00
|
|
|
static final Map<String, MatrixFile> _matrixFileMap = {};
|
2020-04-09 08:00:18 +00:00
|
|
|
MatrixFile get _file => _matrixFileMap[widget.event.eventId];
|
|
|
|
set _file(MatrixFile file) {
|
|
|
|
_matrixFileMap[widget.event.eventId] = file;
|
|
|
|
}
|
|
|
|
|
2020-04-02 12:05:32 +00:00
|
|
|
dynamic _error;
|
|
|
|
|
|
|
|
Future<MatrixFile> _getFile() async {
|
|
|
|
if (_file != null) return _file;
|
2020-05-07 10:14:26 +00:00
|
|
|
return widget.event
|
|
|
|
.downloadAndDecryptAttachment(getThumbnail: widget.event.hasThumbnail);
|
2020-04-02 12:05:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Bubble(
|
|
|
|
padding: BubbleEdges.all(0),
|
|
|
|
radius: Radius.circular(10),
|
2020-04-10 16:12:32 +00:00
|
|
|
color: Theme.of(context).secondaryHeaderColor,
|
2020-04-02 12:05:32 +00:00
|
|
|
elevation: 0,
|
|
|
|
child: Container(
|
2020-04-10 16:12:32 +00:00
|
|
|
height: 300,
|
|
|
|
width: 400,
|
2020-04-02 12:05:32 +00:00
|
|
|
child: Builder(
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
if (_error != null) {
|
|
|
|
return Center(
|
|
|
|
child: Text(
|
|
|
|
_error.toString(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (_file != null) {
|
|
|
|
return InkWell(
|
2020-04-28 12:11:56 +00:00
|
|
|
onTap: () async {
|
|
|
|
final MatrixFile matrixFile =
|
|
|
|
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
|
|
|
widget.event.downloadAndDecryptAttachment(),
|
|
|
|
);
|
|
|
|
matrixFile.open();
|
|
|
|
},
|
2020-04-02 12:05:32 +00:00
|
|
|
child: Image.memory(
|
|
|
|
_file.bytes,
|
2020-04-03 18:32:44 +00:00
|
|
|
fit: BoxFit.cover,
|
2020-04-02 12:05:32 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
_getFile().then((MatrixFile file) {
|
|
|
|
setState(() => _file = file);
|
2020-05-13 13:58:59 +00:00
|
|
|
}, onError: (error, stacktrace) {
|
2020-04-02 12:05:32 +00:00
|
|
|
setState(() => _error = error);
|
|
|
|
});
|
|
|
|
return Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|