2021-03-10 23:02:41 +00:00
|
|
|
/// Chat file tile
|
|
|
|
///
|
|
|
|
/// @author Pierre Hubert
|
|
|
|
import 'package:comunic/models/conversation_message.dart';
|
2021-03-11 19:15:49 +00:00
|
|
|
import 'package:comunic/ui/dialogs/audio_player_dialog.dart';
|
2021-03-11 19:31:06 +00:00
|
|
|
import 'package:comunic/ui/routes/main_route/main_route.dart';
|
|
|
|
import 'package:comunic/ui/routes/video_player_route.dart';
|
2021-03-10 23:02:41 +00:00
|
|
|
import 'package:comunic/ui/widgets/network_image_widget.dart';
|
2021-03-11 16:04:18 +00:00
|
|
|
import 'package:filesize/filesize.dart';
|
2021-03-10 23:02:41 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
|
|
|
|
class ConversationFileWidget extends StatefulWidget {
|
|
|
|
final int messageID;
|
|
|
|
final ConversationMessageFile file;
|
2021-03-10 23:23:11 +00:00
|
|
|
final Color defaultBackgroundColor;
|
2021-03-10 23:02:41 +00:00
|
|
|
|
|
|
|
const ConversationFileWidget({
|
|
|
|
Key key,
|
2021-03-10 23:23:11 +00:00
|
|
|
@required this.defaultBackgroundColor,
|
2021-03-10 23:02:41 +00:00
|
|
|
@required this.messageID,
|
|
|
|
@required this.file,
|
|
|
|
}) : assert(messageID != null),
|
|
|
|
assert(file != null),
|
|
|
|
super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_ConversationFileWidgetState createState() => _ConversationFileWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ConversationFileWidgetState extends State<ConversationFileWidget> {
|
|
|
|
ConversationMessageFile get file => widget.file;
|
|
|
|
|
|
|
|
@override
|
2021-03-10 23:23:11 +00:00
|
|
|
Widget build(BuildContext context) => Container(
|
2021-03-10 23:25:58 +00:00
|
|
|
width: 150,
|
|
|
|
height: 100,
|
2021-03-10 23:23:11 +00:00
|
|
|
child: _buildContent(),
|
|
|
|
);
|
2021-03-10 23:02:41 +00:00
|
|
|
|
2021-03-10 23:13:05 +00:00
|
|
|
Widget _buildContent() {
|
2021-03-10 23:02:41 +00:00
|
|
|
switch (file.fileType) {
|
|
|
|
// Images
|
|
|
|
case ConversationMessageFileType.IMAGE:
|
|
|
|
return Center(
|
|
|
|
child: NetworkImageWidget(
|
|
|
|
url: file.url,
|
|
|
|
thumbnailURL: file.thumbnail,
|
|
|
|
allowFullScreen: true,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-11 19:15:49 +00:00
|
|
|
// We open it in the browser
|
2021-03-10 23:02:41 +00:00
|
|
|
default:
|
2021-03-10 23:23:11 +00:00
|
|
|
return Container(
|
|
|
|
color: widget.defaultBackgroundColor,
|
|
|
|
child: Center(
|
|
|
|
child: MaterialButton(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Spacer(flex: 2),
|
|
|
|
Icon(file.icon, color: Colors.white),
|
|
|
|
Spacer(),
|
|
|
|
Text(file.name, textAlign: TextAlign.center),
|
2021-03-11 16:04:18 +00:00
|
|
|
Spacer(),
|
|
|
|
Text(
|
|
|
|
filesize(file.size),
|
|
|
|
style: TextStyle(fontSize: 10),
|
|
|
|
),
|
2021-03-10 23:23:11 +00:00
|
|
|
Spacer(flex: 2),
|
|
|
|
],
|
|
|
|
),
|
2021-03-11 19:15:49 +00:00
|
|
|
onPressed: _openFile,
|
2021-03-10 23:02:41 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-03-11 19:15:49 +00:00
|
|
|
|
|
|
|
void _openFile() {
|
|
|
|
switch (file.fileType) {
|
|
|
|
case ConversationMessageFileType.AUDIO:
|
|
|
|
showAudioPlayerDialog(context, file.url);
|
|
|
|
break;
|
|
|
|
|
2021-03-11 19:31:06 +00:00
|
|
|
case ConversationMessageFileType.VIDEO:
|
|
|
|
MainController.of(context).push(
|
|
|
|
VideoPlayerRoute(url: file.url),
|
|
|
|
hideNavBar: true,
|
|
|
|
canShowAsDialog: true,
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2021-03-11 19:15:49 +00:00
|
|
|
default:
|
|
|
|
launch(file.url);
|
|
|
|
}
|
|
|
|
}
|
2021-03-10 23:02:41 +00:00
|
|
|
}
|