webFilePicker function
Future<void>
webFilePicker({
- required BuildContext context,
- required Function onUploadSuccess,
- required SendMessage widget,
Implementation
Future<void> webFilePicker({
required BuildContext context,
required Function onUploadSuccess,
required SendMessage widget,
}) async {
try {
var picked = await FilePicker.platform.pickFiles();
if (picked?.files.first.bytes != null) {
Alert.show(
widget.props.translations.attachmentUploadingText,
context,
textStyle: widget.props.style.chatUploadingAlertTextStyle ??
Theme.of(context).textTheme.bodyText2,
backgroundColor: widget.props.style.chatUploadingAlertBackgroundColor ??
Theme.of(context).bottomAppBarColor,
gravity: Alert.bottom,
duration: Alert.lengthLong,
);
List<PapercupsAttachment> attachments = await uploadFile(
widget.props,
fileBytes: picked!.files.first.bytes,
fileName: picked.files.first.name,
);
onUploadSuccess(attachments);
}
} on Exception catch (_) {
Alert.show(
widget.props.translations.attachmentUploadErrorText,
context,
textStyle: widget.props.style.chatUploadErrorAlertTextStyle ??
Theme.of(context).textTheme.bodyText2,
backgroundColor: widget.props.style.chatUploadErrorAlertBackgroundColor ??
Theme.of(context).bottomAppBarColor,
gravity: Alert.bottom,
duration: Alert.lengthLong,
);
}
}