chat attachment added.
parent
c5b4325aec
commit
7445902564
@ -0,0 +1,138 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:audio_waveforms/audio_waveforms.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:test_sa/extensions/text_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||||
|
import 'package:test_sa/modules/cx_module/chat/api_client.dart';
|
||||||
|
import 'package:test_sa/modules/cx_module/chat/chat_api_client.dart';
|
||||||
|
import 'package:test_sa/modules/cx_module/chat/model/get_single_user_chat_list_model.dart';
|
||||||
|
|
||||||
|
import '../../../../new_views/app_style/app_color.dart';
|
||||||
|
|
||||||
|
class ChatAudioPlayer extends StatefulWidget {
|
||||||
|
String downloadURl;
|
||||||
|
FileTypeResponse file;
|
||||||
|
bool isLocalFile;
|
||||||
|
|
||||||
|
ChatAudioPlayer(this.file, this.downloadURl, {Key? key, this.isLocalFile = false}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_ChatAudioPlayerState createState() {
|
||||||
|
return _ChatAudioPlayerState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ChatAudioPlayerState extends State<ChatAudioPlayer> {
|
||||||
|
bool downloading = false;
|
||||||
|
|
||||||
|
PlayerController playerController = PlayerController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
checkFileInLocalStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
File? audioFile;
|
||||||
|
List<double> waveformData = [];
|
||||||
|
|
||||||
|
void checkFileInLocalStorage() async {
|
||||||
|
Directory tempDir = await getTemporaryDirectory();
|
||||||
|
String tempPath = '${tempDir.path}/${widget.file.fileName}';
|
||||||
|
File tempFile = File(tempPath);
|
||||||
|
bool exists = await tempFile.exists();
|
||||||
|
if (exists) {
|
||||||
|
audioFile = tempFile;
|
||||||
|
playerController = PlayerController();
|
||||||
|
await playerController.preparePlayer(path: tempPath);
|
||||||
|
waveformData = await playerController.extractWaveformData(path: tempPath);
|
||||||
|
} else {
|
||||||
|
downloadFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void downloadFile() async {
|
||||||
|
downloading = true;
|
||||||
|
setState(() {});
|
||||||
|
try {
|
||||||
|
// Uint8List list = await ChatApiClient().downloadFileWithHttp(widget.downloadURl, fileName: widget.file.fileName, fileTypeDescription: widget.file.fileTypeDescription, fileSource: widget.file.fileTypeId!);
|
||||||
|
// audioFile = File.fromRawPath(list);
|
||||||
|
|
||||||
|
audioFile =
|
||||||
|
await ChatApiClient().downloadFileWithHttp(widget.downloadURl, fileName: widget.file.fileName, fileTypeDescription: widget.file.fileTypeDescription, fileSource: widget.file.fileTypeId!);
|
||||||
|
|
||||||
|
playerController = PlayerController();
|
||||||
|
await playerController.preparePlayer(path: audioFile!.path);
|
||||||
|
waveformData = await playerController.extractWaveformData(path: audioFile!.path);
|
||||||
|
} catch (ex) {
|
||||||
|
print(ex);
|
||||||
|
audioFile = null;
|
||||||
|
}
|
||||||
|
downloading = false;
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
playerController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(
|
||||||
|
height: 56,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
if (downloading)
|
||||||
|
const SizedBox(
|
||||||
|
height: 24,
|
||||||
|
width: 24,
|
||||||
|
child: CircularProgressIndicator(color: AppColor.primary10, strokeWidth: 2),
|
||||||
|
)
|
||||||
|
else if (playerController.playerState == PlayerState.playing)
|
||||||
|
IconButton(
|
||||||
|
onPressed: () async {
|
||||||
|
await playerController.pausePlayer();
|
||||||
|
await playerController.stopPlayer();
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
style: const ButtonStyle(
|
||||||
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap, // or .padded
|
||||||
|
),
|
||||||
|
icon: const Icon(Icons.stop_circle_outlined, size: 20),
|
||||||
|
constraints: const BoxConstraints(),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
IconButton(
|
||||||
|
onPressed: () async {
|
||||||
|
await playerController.startPlayer();
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
style: const ButtonStyle(
|
||||||
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap, // or .padded
|
||||||
|
),
|
||||||
|
icon: const Icon(Icons.play_circle_fill_rounded, size: 20),
|
||||||
|
constraints: const BoxConstraints(),
|
||||||
|
),
|
||||||
|
AudioFileWaveforms(
|
||||||
|
playerController: playerController,
|
||||||
|
waveformData: waveformData,
|
||||||
|
enableSeekGesture: false,
|
||||||
|
continuousWaveform: false,
|
||||||
|
waveformType: WaveformType.long,
|
||||||
|
playerWaveStyle: const PlayerWaveStyle(
|
||||||
|
fixedWaveColor: AppColor.neutral50,
|
||||||
|
liveWaveColor: AppColor.primary10,
|
||||||
|
showSeekLine: true,
|
||||||
|
),
|
||||||
|
size: Size(MediaQuery.of(context).size.width, 56.0),
|
||||||
|
).expanded,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,436 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:file_picker/file_picker.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
|
import 'package:image_cropper/image_cropper.dart';
|
||||||
|
import 'package:image_picker/image_picker.dart';
|
||||||
|
import 'package:test_sa/extensions/context_extension.dart';
|
||||||
|
import 'package:test_sa/extensions/int_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/text_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||||
|
import 'package:test_sa/models/generic_attachment_model.dart';
|
||||||
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
||||||
|
|
||||||
|
class ChatFilePicker extends StatelessWidget {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
"Attach File".heading4(context),
|
||||||
|
12.height,
|
||||||
|
GridView(
|
||||||
|
padding: const EdgeInsets.all(0),
|
||||||
|
shrinkWrap: true,
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1, crossAxisSpacing: 12, mainAxisSpacing: 12),
|
||||||
|
children: <Widget>[
|
||||||
|
gridItem(Icons.camera_enhance_rounded, context.translation.pickFromCamera).onPress(() async {
|
||||||
|
await fromMediaPicker(context, ImageSource.camera);
|
||||||
|
}),
|
||||||
|
gridItem(Icons.image_rounded, context.translation.pickFromGallery).onPress(() async {
|
||||||
|
await fromMediaPicker(context, ImageSource.gallery);
|
||||||
|
}),
|
||||||
|
gridItem(Icons.file_present_rounded, context.translation.pickFromFiles).onPress(() async {
|
||||||
|
await fromFilePicker(context);
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
12.height,
|
||||||
|
],
|
||||||
|
).paddingAll(21);
|
||||||
|
}
|
||||||
|
|
||||||
|
fromMediaPicker(BuildContext context, ImageSource imageSource) async {
|
||||||
|
XFile? pickedFile = await ImagePicker().pickImage(source: imageSource, imageQuality: 70, maxWidth: 800, maxHeight: 800);
|
||||||
|
if (pickedFile != null) {
|
||||||
|
CroppedFile? croppedFile = await ImageCropper().cropImage(
|
||||||
|
sourcePath: pickedFile.path,
|
||||||
|
aspectRatio: CropAspectRatio(ratioX: 1, ratioY: 1),
|
||||||
|
uiSettings: [
|
||||||
|
AndroidUiSettings(
|
||||||
|
toolbarTitle: 'ATOMS',
|
||||||
|
toolbarColor: Colors.white,
|
||||||
|
toolbarWidgetColor: context.settingProvider.theme == "dark" ? AppColor.neutral10 : AppColor.neutral50,
|
||||||
|
initAspectRatio: CropAspectRatioPreset.square,
|
||||||
|
lockAspectRatio: false,
|
||||||
|
),
|
||||||
|
IOSUiSettings(title: 'ATOMS'),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
if (croppedFile != null) {
|
||||||
|
Navigator.pop(context, File(croppedFile.path));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
fromFilePicker(BuildContext context) async {
|
||||||
|
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||||
|
type: FileType.custom,
|
||||||
|
allowedExtensions: ['jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'xlsx', 'pptx'],
|
||||||
|
);
|
||||||
|
if ((result?.paths ?? []).isNotEmpty) {
|
||||||
|
Navigator.pop(context, File(result!.paths.first!));
|
||||||
|
} else {
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget gridItem(IconData iconData, String title) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
border: Border.all(color: const Color(0xffF1F1F1), width: 1),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Icon(iconData, color: const Color(0xff7D859A), size: 36),
|
||||||
|
Text(
|
||||||
|
title,
|
||||||
|
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// static Future<File?> selectFile(BuildContext context) async {
|
||||||
|
// ImageSource source = (await showModalBottomSheet(
|
||||||
|
// context: context,
|
||||||
|
// shape: const RoundedRectangleBorder(
|
||||||
|
// borderRadius: BorderRadius.vertical(
|
||||||
|
// top: Radius.circular(20),
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// clipBehavior: Clip.antiAliasWithSaveLayer,
|
||||||
|
// builder: (BuildContext context) => ChatFilePicker())) as ImageSource;
|
||||||
|
//
|
||||||
|
// final pickedFile = await ImagePicker().pickImage(source: source, imageQuality: 70, maxWidth: 800, maxHeight: 800);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// class AttachmentPicker extends StatefulWidget {
|
||||||
|
// final String label;
|
||||||
|
// final bool error;
|
||||||
|
// final List<GenericAttachmentModel> attachment;
|
||||||
|
//
|
||||||
|
// final bool enabled, onlyImages;
|
||||||
|
// double? buttonHeight;
|
||||||
|
// Widget? buttonIcon;
|
||||||
|
// Color? buttonColor;
|
||||||
|
// final Function(List<GenericAttachmentModel>)? onChange;
|
||||||
|
// final bool showAsGrid;
|
||||||
|
//
|
||||||
|
// AttachmentPicker(
|
||||||
|
// {Key? key,
|
||||||
|
// this.attachment = const <GenericAttachmentModel>[],
|
||||||
|
// required this.label,
|
||||||
|
// this.error = false,
|
||||||
|
// this.buttonHeight,
|
||||||
|
// this.buttonIcon,
|
||||||
|
// this.enabled = true,
|
||||||
|
// this.onlyImages = false,
|
||||||
|
// this.onChange,
|
||||||
|
// this.showAsGrid = false,
|
||||||
|
// this.buttonColor})
|
||||||
|
// : super(key: key);
|
||||||
|
//
|
||||||
|
// @override
|
||||||
|
// State<AttachmentPicker> createState() => _AttachmentPickerState();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// class _AttachmentPickerState extends State<AttachmentPicker> {
|
||||||
|
// @override
|
||||||
|
// Widget build(BuildContext context) {
|
||||||
|
// return Column(
|
||||||
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
// children: [
|
||||||
|
// AppDashedButton(
|
||||||
|
// title: widget.label,
|
||||||
|
// height: widget.buttonHeight,
|
||||||
|
// buttonColor: widget.buttonColor,
|
||||||
|
// icon: widget.buttonIcon,
|
||||||
|
// onPressed: (widget.enabled == false)
|
||||||
|
// ? () {}
|
||||||
|
// : widget.showAsGrid
|
||||||
|
// ? showFileSourceSheet
|
||||||
|
// : onFilePicker),
|
||||||
|
// 16.height,
|
||||||
|
// if (widget.attachment.isNotEmpty)
|
||||||
|
// Wrap(
|
||||||
|
// spacing: 8.toScreenWidth,
|
||||||
|
// children: List.generate(
|
||||||
|
// widget.attachment.length,
|
||||||
|
// (index) {
|
||||||
|
// File image = File(widget.attachment[index].name!);
|
||||||
|
// return MultiFilesPickerItem(
|
||||||
|
// file: image,
|
||||||
|
// enabled: widget.enabled,
|
||||||
|
// onRemoveTap: (image) {
|
||||||
|
// if (!widget.enabled) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// widget.attachment.removeAt(index);
|
||||||
|
// if (widget.onChange != null) {
|
||||||
|
// widget.onChange!(widget.attachment);
|
||||||
|
// }
|
||||||
|
// setState(() {});
|
||||||
|
// },
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// ],
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// fromFilePicker() async {
|
||||||
|
// FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||||
|
// type: FileType.custom,
|
||||||
|
// allowMultiple: true,
|
||||||
|
// allowedExtensions: widget.onlyImages ? ['jpg', 'jpeg', 'png'] : ['jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'xlsx', 'pptx'],
|
||||||
|
// );
|
||||||
|
// if (result != null) {
|
||||||
|
// for (var path in result.paths) {
|
||||||
|
// widget.attachment.add(GenericAttachmentModel(id: 0, name: File(path!).path));
|
||||||
|
// }
|
||||||
|
// if (widget.onChange != null) {
|
||||||
|
// widget.onChange!(widget.attachment);
|
||||||
|
// }
|
||||||
|
// setState(() {});
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// void showFileSourceSheet() async {
|
||||||
|
// // if (widget.attachment.length >= 5) {
|
||||||
|
// // Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5);
|
||||||
|
// // return;
|
||||||
|
// // }
|
||||||
|
//
|
||||||
|
// ImageSource source = (await showModalBottomSheet(
|
||||||
|
// context: context,
|
||||||
|
// shape: const RoundedRectangleBorder(
|
||||||
|
// borderRadius: BorderRadius.vertical(
|
||||||
|
// top: Radius.circular(20),
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// clipBehavior: Clip.antiAliasWithSaveLayer,
|
||||||
|
// builder: (BuildContext context) => Column(
|
||||||
|
// mainAxisSize: MainAxisSize.min,
|
||||||
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
// children: [
|
||||||
|
// "Attach File".heading4(context),
|
||||||
|
// 12.height,
|
||||||
|
// GridView(
|
||||||
|
// padding: const EdgeInsets.all(0),
|
||||||
|
// shrinkWrap: true,
|
||||||
|
// physics: const NeverScrollableScrollPhysics(),
|
||||||
|
// gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1, crossAxisSpacing: 12, mainAxisSpacing: 12),
|
||||||
|
// children: <Widget>[
|
||||||
|
// gridItem(Icons.camera_enhance_rounded, context.translation.pickFromCamera).onPress(() => Navigator.of(context).pop(ImageSource.camera)),
|
||||||
|
// gridItem(Icons.image_rounded, context.translation.pickFromGallery).onPress(() => Navigator.of(context).pop(ImageSource.gallery)),
|
||||||
|
// gridItem(Icons.file_present_rounded, context.translation.pickFromFiles).onPress(() async {
|
||||||
|
// await fromFilePicker();
|
||||||
|
// Navigator.pop(context);
|
||||||
|
// }),
|
||||||
|
// ],
|
||||||
|
// ),
|
||||||
|
// 12.height,
|
||||||
|
// ],
|
||||||
|
// ).paddingAll(21),
|
||||||
|
// )) as ImageSource;
|
||||||
|
//
|
||||||
|
// final pickedFile = await ImagePicker().pickImage(source: source, imageQuality: 70, maxWidth: 800, maxHeight: 800);
|
||||||
|
//
|
||||||
|
// if (pickedFile != null) {
|
||||||
|
// File fileImage = File(pickedFile.path);
|
||||||
|
// widget.attachment.add(GenericAttachmentModel(id: 0, name: fileImage.path));
|
||||||
|
// if (widget.onChange != null) {
|
||||||
|
// widget.onChange!(widget.attachment);
|
||||||
|
// }
|
||||||
|
// setState(() {});
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Widget gridItem(IconData iconData, String title) {
|
||||||
|
// return Container(
|
||||||
|
// padding: const EdgeInsets.all(12),
|
||||||
|
// decoration: BoxDecoration(
|
||||||
|
// color: Colors.white,
|
||||||
|
// borderRadius: BorderRadius.circular(12),
|
||||||
|
// border: Border.all(color: const Color(0xffF1F1F1), width: 1),
|
||||||
|
// ),
|
||||||
|
// child: Column(
|
||||||
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
// children: [
|
||||||
|
// Icon(iconData, color: const Color(0xff7D859A), size: 36),
|
||||||
|
// Text(
|
||||||
|
// title,
|
||||||
|
// style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
|
||||||
|
// ),
|
||||||
|
// ],
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// onFilePicker() async {
|
||||||
|
// //TODO removed on request by Backend as they don't have anyissue with large number of files
|
||||||
|
// // if (widget.attachment.length >= 5) {
|
||||||
|
// // Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5);
|
||||||
|
// // return;
|
||||||
|
// // }
|
||||||
|
// ImageSource? source = await showModalBottomSheet<ImageSource>(
|
||||||
|
// context: context,
|
||||||
|
// builder: (BuildContext context) {
|
||||||
|
// Widget listCard({required String icon, required String label, required VoidCallback onTap}) {
|
||||||
|
// return Container(
|
||||||
|
// padding: const EdgeInsets.all(12),
|
||||||
|
// decoration: BoxDecoration(
|
||||||
|
// color: AppColor.background(context),
|
||||||
|
// // color: Colors.white,
|
||||||
|
// borderRadius: BorderRadius.circular(12),
|
||||||
|
// border: Border.all(color: const Color(0xffF1F1F1), width: 1),
|
||||||
|
// ),
|
||||||
|
// child: Column(
|
||||||
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
// children: [
|
||||||
|
// icon.toSvgAsset(color: AppColor.iconColor(context), width: 36, height: 36),
|
||||||
|
// // Icon(iconData, color: const Color(0xff7D859A), size: 36),
|
||||||
|
// Text(
|
||||||
|
// label,
|
||||||
|
// style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
|
||||||
|
// ),
|
||||||
|
// ],
|
||||||
|
// ),
|
||||||
|
// ).onPress(onTap);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return SafeArea(
|
||||||
|
// top: false,
|
||||||
|
// child: Container(
|
||||||
|
// width: double.infinity,
|
||||||
|
// color: AppColor.background(context),
|
||||||
|
// child: Column(
|
||||||
|
// mainAxisSize: MainAxisSize.min,
|
||||||
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
// children: [
|
||||||
|
// "Attach File".heading4(context),
|
||||||
|
// 12.height,
|
||||||
|
// GridView(
|
||||||
|
// padding: const EdgeInsets.all(0),
|
||||||
|
// shrinkWrap: true,
|
||||||
|
// physics: const NeverScrollableScrollPhysics(),
|
||||||
|
// gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1, crossAxisSpacing: 12, mainAxisSpacing: 12),
|
||||||
|
// children: <Widget>[
|
||||||
|
// listCard(
|
||||||
|
// icon: 'camera_icon',
|
||||||
|
// label: '${context.translation.open}\n${context.translation.camera}',
|
||||||
|
// onTap: () {
|
||||||
|
// Navigator.of(context).pop(ImageSource.camera);
|
||||||
|
// },
|
||||||
|
// ),
|
||||||
|
// listCard(
|
||||||
|
// icon: 'gallery_icon',
|
||||||
|
// label: '${context.translation.open}\n${context.translation.gallery}',
|
||||||
|
// onTap: () {
|
||||||
|
// Navigator.of(context).pop(ImageSource.gallery);
|
||||||
|
// },
|
||||||
|
// ),
|
||||||
|
// listCard(
|
||||||
|
// icon: 'file_icon',
|
||||||
|
// label: '${context.translation.open}\n${context.translation.files}',
|
||||||
|
// onTap: () async {
|
||||||
|
// await fromFilePicker();
|
||||||
|
// Navigator.pop(context);
|
||||||
|
// },
|
||||||
|
// ),
|
||||||
|
// ],
|
||||||
|
// ),
|
||||||
|
// // Container(
|
||||||
|
// // padding: const EdgeInsets.all(16.0),
|
||||||
|
// // child: Row(
|
||||||
|
// // mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
// // children: <Widget>[
|
||||||
|
// // listCard(
|
||||||
|
// // icon: 'camera_icon',
|
||||||
|
// // label: '${context.translation.open}\n${context.translation.camera}',
|
||||||
|
// // onTap: () {
|
||||||
|
// // Navigator.of(context).pop(ImageSource.camera);
|
||||||
|
// // },
|
||||||
|
// // ),
|
||||||
|
// // listCard(
|
||||||
|
// // icon: 'gallery_icon',
|
||||||
|
// // label: '${context.translation.open}\n${context.translation.gallery}',
|
||||||
|
// // onTap: () {
|
||||||
|
// // Navigator.of(context).pop(ImageSource.gallery);
|
||||||
|
// // },
|
||||||
|
// // ),
|
||||||
|
// // listCard(
|
||||||
|
// // icon: 'file_icon',
|
||||||
|
// // label: '${context.translation.open}\n${context.translation.files}',
|
||||||
|
// // onTap: () async {
|
||||||
|
// // await fromFilePicker();
|
||||||
|
// // Navigator.pop(context);
|
||||||
|
// // },
|
||||||
|
// // ),
|
||||||
|
// // ],
|
||||||
|
// // ),
|
||||||
|
// // ),
|
||||||
|
// ],
|
||||||
|
// ).paddingAll(16),
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
// );
|
||||||
|
// // ImageSource source = await showDialog(
|
||||||
|
// // context: context,
|
||||||
|
// // builder: (dialogContext) => CupertinoAlertDialog(
|
||||||
|
// // actions: <Widget>[
|
||||||
|
// // TextButton(
|
||||||
|
// // child: Text(context.translation.pickFromCamera),
|
||||||
|
// // onPressed: () {
|
||||||
|
// // Navigator.of(dialogContext).pop(ImageSource.camera);
|
||||||
|
// // },
|
||||||
|
// // ),
|
||||||
|
// // TextButton(
|
||||||
|
// // child: Text(context.translation.pickFromGallery),
|
||||||
|
// // onPressed: () {
|
||||||
|
// // Navigator.of(dialogContext).pop(ImageSource.gallery);
|
||||||
|
// // },
|
||||||
|
// // ),
|
||||||
|
// // TextButton(
|
||||||
|
// // child: Text(context.translation.pickFromFiles),
|
||||||
|
// // onPressed: () async {
|
||||||
|
// // await fromFilePicker();
|
||||||
|
// // Navigator.pop(context);
|
||||||
|
// // },
|
||||||
|
// // ),
|
||||||
|
// // ],
|
||||||
|
// // ),
|
||||||
|
// // );
|
||||||
|
// if (source == null) return;
|
||||||
|
//
|
||||||
|
// final pickedFile = await ImagePicker().pickImage(source: source, imageQuality: 70, maxWidth: 800, maxHeight: 800);
|
||||||
|
//
|
||||||
|
// if (pickedFile != null) {
|
||||||
|
// File fileImage = File(pickedFile.path);
|
||||||
|
// widget.attachment.add(GenericAttachmentModel(id: 0, name: fileImage.path));
|
||||||
|
// if (widget.onChange != null) {
|
||||||
|
// widget.onChange!(widget.attachment);
|
||||||
|
// }
|
||||||
|
// setState(() {});
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// setState(() {});
|
||||||
|
// }
|
||||||
|
// }
|
||||||
@ -0,0 +1,137 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:open_file/open_file.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:test_sa/extensions/context_extension.dart';
|
||||||
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||||
|
import 'package:test_sa/modules/cx_module/chat/chat_api_client.dart';
|
||||||
|
import 'package:test_sa/modules/cx_module/chat/chat_provider.dart';
|
||||||
|
import 'package:test_sa/modules/cx_module/chat/model/get_single_user_chat_list_model.dart';
|
||||||
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
||||||
|
import 'package:test_sa/new_views/app_style/app_text_style.dart';
|
||||||
|
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
||||||
|
import 'package:test_sa/views/widgets/images/multi_image_picker_item.dart';
|
||||||
|
import 'package:test_sa/views/widgets/sound/sound_player.dart';
|
||||||
|
|
||||||
|
class ChatFileViewer extends StatelessWidget {
|
||||||
|
String downloadUrl;
|
||||||
|
FileTypeResponse fileTypeResponse;
|
||||||
|
|
||||||
|
ChatFileViewer(this.downloadUrl, this.fileTypeResponse, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return FutureBuilder<File?>(
|
||||||
|
future: checkFileInLocalStorage(),
|
||||||
|
builder: (BuildContext context, AsyncSnapshot<File?> snapshot) {
|
||||||
|
if (snapshot.connectionState != ConnectionState.waiting && snapshot.hasData) {}
|
||||||
|
|
||||||
|
if (fileTypeResponse!.fileKind.toString().toLowerCase() == "audio") {
|
||||||
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
|
return Container(
|
||||||
|
width: 48,
|
||||||
|
height: 48,
|
||||||
|
decoration: ShapeDecoration(
|
||||||
|
color: AppColor.background(context),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
side: BorderSide(width: 1, color: (context.isDark ? AppColor.neutral20 : AppColor.neutral30)),
|
||||||
|
borderRadius: BorderRadius.circular(32),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: const CircularProgressIndicator(color: AppColor.primary10, strokeWidth: 2).center,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (snapshot.data == null) {
|
||||||
|
return Text("Failed to load", style: AppTextStyle.tiny.copyWith(color: context.isDark ? AppColor.red50 : AppColor.red60));
|
||||||
|
}
|
||||||
|
return ASoundPlayer(audio: snapshot.data!.path);
|
||||||
|
}
|
||||||
|
return Container(
|
||||||
|
width: 180,
|
||||||
|
height: 180,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
border: Border.all(color: Colors.grey.withOpacity(.5), width: 1),
|
||||||
|
image: snapshot.hasData ? DecorationImage(fit: BoxFit.contain, image: getImage(snapshot.data!)) : null,
|
||||||
|
),
|
||||||
|
child: snapshot.connectionState == ConnectionState.waiting
|
||||||
|
? const SizedBox(
|
||||||
|
height: 24,
|
||||||
|
width: 24,
|
||||||
|
child: CircularProgressIndicator(color: AppColor.primary10, strokeWidth: 2),
|
||||||
|
).center
|
||||||
|
: snapshot.hasData
|
||||||
|
? getFile(context, snapshot.data!)
|
||||||
|
: const Icon(Icons.broken_image_rounded),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget getFile(BuildContext context, File file) {
|
||||||
|
bool isImage = file.path.split(".").last.toLowerCase() == "png" || file.path.split(".").last.toLowerCase() == "jpg" || file.path.split(".").last.toLowerCase() == "jpeg";
|
||||||
|
bool isPdf = file.path.split(".").last.toLowerCase() == "pdf";
|
||||||
|
bool isExcel = file.path.split(".").last.toLowerCase() == "xlsx";
|
||||||
|
|
||||||
|
return MaterialButton(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
onPressed: () async {
|
||||||
|
if (isImage) {
|
||||||
|
Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (_) => Scaffold(
|
||||||
|
appBar: const DefaultAppBar(),
|
||||||
|
body: SafeArea(
|
||||||
|
child: InteractiveViewer(child: Image.file(file)).center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
OpenFile.open(file.path);
|
||||||
|
}
|
||||||
|
// else {
|
||||||
|
// // if (!await launchUrl(Uri.parse(URLs.getFileUrl(file.path)!), mode: LaunchMode.externalApplication)) {
|
||||||
|
// // Fluttertoast.showToast(msg: "UnExpected Error with file.");
|
||||||
|
// // throw Exception('Could not launch');
|
||||||
|
// // }
|
||||||
|
// }
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageProvider getImage(File file) {
|
||||||
|
bool isImage = file.path.split(".").last.toLowerCase() == "png" || file.path.split(".").last.toLowerCase() == "jpg" || file.path.split(".").last.toLowerCase() == "jpeg";
|
||||||
|
bool isPdf = file.path.split(".").last.toLowerCase() == "pdf";
|
||||||
|
bool isExcel = file.path.split(".").last.toLowerCase() == "xlsx";
|
||||||
|
|
||||||
|
if (isImage) {
|
||||||
|
return FileImage(file);
|
||||||
|
}
|
||||||
|
return AssetImage("assets/images/${isPdf ? "pdf" : isExcel ? "excel" : "doc"}.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<File?> checkFileInLocalStorage() async {
|
||||||
|
Directory tempDir = await getTemporaryDirectory();
|
||||||
|
String tempPath = '${tempDir.path}/${fileTypeResponse.fileName}';
|
||||||
|
File tempFile = File(tempPath);
|
||||||
|
bool exists = await tempFile.exists();
|
||||||
|
if (exists) {
|
||||||
|
return tempFile;
|
||||||
|
} else {
|
||||||
|
return downloadFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<File?> downloadFile() async {
|
||||||
|
try {
|
||||||
|
return await ChatApiClient()
|
||||||
|
.downloadFileWithHttp(downloadUrl, fileName: fileTypeResponse.fileName, fileTypeDescription: fileTypeResponse.fileTypeDescription, fileSource: fileTypeResponse.fileTypeId!);
|
||||||
|
} catch (ex) {
|
||||||
|
print("downloadFile:$ex");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:test_sa/extensions/context_extension.dart';
|
||||||
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||||
|
import 'package:test_sa/modules/cx_module/chat/chat_provider.dart';
|
||||||
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
||||||
|
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
||||||
|
|
||||||
|
class ViewAllAttachmentPage extends StatefulWidget {
|
||||||
|
int moduleId;
|
||||||
|
int requestId;
|
||||||
|
|
||||||
|
ViewAllAttachmentPage({required this.moduleId, required this.requestId, Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_ViewAllAttachmentPageState createState() {
|
||||||
|
return _ViewAllAttachmentPageState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ViewAllAttachmentPageState extends State<ViewAllAttachmentPage> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
Provider.of<ChatProvider>(context, listen: false).viewAllDocuments(widget.moduleId, widget.requestId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: AppColor.neutral100,
|
||||||
|
appBar: const DefaultAppBar(title: "Documents"),
|
||||||
|
body: FutureBuilder(
|
||||||
|
future: Provider.of<ChatProvider>(context, listen: false).viewAllDocuments(widget.moduleId, widget.requestId),
|
||||||
|
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
||||||
|
bool isLoading = false;
|
||||||
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
|
isLoading = true;
|
||||||
|
}
|
||||||
|
return GridView.builder(
|
||||||
|
itemCount: 9, //isLoading? 9: 2,
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: context.isTablet() ? 4 : 3, childAspectRatio: 1, crossAxisSpacing: 8, mainAxisSpacing: 8),
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
return Container().toShimmer(context: context, isShow: isLoading);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:test_sa/extensions/int_extensions.dart';
|
||||||
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
||||||
|
import 'package:test_sa/views/app_style/sizing.dart';
|
||||||
|
|
||||||
|
class UploadingDialog extends StatelessWidget {
|
||||||
|
const UploadingDialog({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Center(
|
||||||
|
child: Container(
|
||||||
|
height: 150.toScreenWidth,
|
||||||
|
width: 200.toScreenWidth,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: AppColor.neutral30,
|
||||||
|
borderRadius: BorderRadius.circular(20.0),
|
||||||
|
boxShadow: [AppStyle.boxShadow],
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const CircularProgressIndicator(strokeWidth: 3),
|
||||||
|
16.height,
|
||||||
|
Text(
|
||||||
|
"Uploading...",
|
||||||
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: AppColor.textColor(context), height: 35 / 24, letterSpacing: -0.96),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue