mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-30 00:36:28 +00:00
102 lines
2.8 KiB
Dart
102 lines
2.8 KiB
Dart
/// Chat file tile
|
|
///
|
|
/// @author Pierre Hubert
|
|
import 'package:comunic/models/conversation_message.dart';
|
|
import 'package:comunic/ui/dialogs/audio_player_dialog.dart';
|
|
import 'package:comunic/ui/routes/main_route/main_route.dart';
|
|
import 'package:comunic/ui/routes/video_player_route.dart';
|
|
import 'package:comunic/ui/widgets/network_image_widget.dart';
|
|
import 'package:filesize/filesize.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
class ConversationFileWidget extends StatefulWidget {
|
|
final int messageID;
|
|
final ConversationMessageFile file;
|
|
final Color defaultBackgroundColor;
|
|
|
|
const ConversationFileWidget({
|
|
Key key,
|
|
@required this.defaultBackgroundColor,
|
|
@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
|
|
Widget build(BuildContext context) => Container(
|
|
width: 150,
|
|
height: 100,
|
|
child: _buildContent(),
|
|
);
|
|
|
|
Widget _buildContent() {
|
|
switch (file.fileType) {
|
|
// Images
|
|
case ConversationMessageFileType.IMAGE:
|
|
return Center(
|
|
child: NetworkImageWidget(
|
|
url: file.url,
|
|
thumbnailURL: file.thumbnail,
|
|
allowFullScreen: true,
|
|
),
|
|
);
|
|
|
|
// We open it in the browser
|
|
default:
|
|
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),
|
|
Spacer(),
|
|
Text(
|
|
filesize(file.size),
|
|
style: TextStyle(fontSize: 10),
|
|
),
|
|
Spacer(flex: 2),
|
|
],
|
|
),
|
|
onPressed: _openFile,
|
|
),
|
|
),
|
|
);
|
|
break;
|
|
}
|
|
}
|
|
|
|
void _openFile() {
|
|
switch (file.fileType) {
|
|
case ConversationMessageFileType.AUDIO:
|
|
showAudioPlayerDialog(context, file.url);
|
|
break;
|
|
|
|
case ConversationMessageFileType.VIDEO:
|
|
MainController.of(context).push(
|
|
VideoPlayerRoute(url: file.url),
|
|
hideNavBar: true,
|
|
canShowAsDialog: true,
|
|
);
|
|
break;
|
|
|
|
default:
|
|
launch(file.url);
|
|
}
|
|
}
|
|
}
|