284 lines
8.8 KiB
Dart
284 lines
8.8 KiB
Dart
// import 'dart:io';
|
|
// import 'dart:math';
|
|
// import 'package:cached_network_image/cached_network_image.dart';
|
|
// import 'package:flutter/material.dart';
|
|
// import 'package:get/get.dart';
|
|
// import 'package:scaffold/constants/message_constant.dart';
|
|
// import 'package:scaffold/utils/ui_tools.dart';
|
|
// import 'package:scaffold/views/im/conversation/preview/index_page.dart';
|
|
// import 'package:scaffold/views/moments/index/widgets/media_preview.dart';
|
|
// import 'package:tencent_im_sdk_plugin/models/v2_tim_image.dart';
|
|
// import 'package:tencent_im_sdk_plugin/models/v2_tim_message.dart';
|
|
// import 'package:transparent_image/transparent_image.dart';
|
|
|
|
// class ShowImageMessage extends StatefulWidget {
|
|
// final V2TimMessage message;
|
|
|
|
// const ShowImageMessage(this.message, {Key? key}) : super(key: key);
|
|
|
|
// @override
|
|
// State<ShowImageMessage> createState() => _ShowImageMessageState();
|
|
// }
|
|
|
|
// class _ShowImageMessageState extends State<ShowImageMessage> {
|
|
// bool imageIsRender = false;
|
|
|
|
// @override
|
|
// didUpdateWidget(oldWidget) {
|
|
// var oldImgListLength = oldWidget.message.imageElem?.imageList?.length ?? 0;
|
|
// var currImgListLength = widget.message.imageElem?.imageList?.length ?? 0;
|
|
// if (currImgListLength == 1 && oldImgListLength == 0) {
|
|
// setState(() {
|
|
// imageIsRender = true;
|
|
// });
|
|
// }
|
|
// super.didUpdateWidget(oldWidget);
|
|
// }
|
|
|
|
// @override
|
|
// Widget build(BuildContext context) {
|
|
// V2TimImage? originalImg =
|
|
// getImageFromList(V2_TIM_IMAGE_TYPES_ENUM.original);
|
|
// V2TimImage? smallImg = getImageFromList(V2_TIM_IMAGE_TYPES_ENUM.small);
|
|
|
|
// return Container(
|
|
// decoration: BoxDecoration(
|
|
// borderRadius: const BorderRadius.all(Radius.circular(4)),
|
|
// border: Border.all(
|
|
// color: const Color.fromRGBO(245, 166, 35, 0),
|
|
// width: 2,
|
|
// ),
|
|
// ),
|
|
// child: LayoutBuilder(
|
|
// builder: (BuildContext context, BoxConstraints constraints) {
|
|
// return ConstrainedBox(
|
|
// constraints: BoxConstraints(
|
|
// maxWidth: constraints.maxWidth * 0.5,
|
|
// minWidth: 64,
|
|
// maxHeight: 256,
|
|
// ),
|
|
// child: imageBuilder(
|
|
// originalImg: originalImg,
|
|
// smallImg: smallImg,
|
|
// ),
|
|
// );
|
|
// },
|
|
// ),
|
|
// );
|
|
// }
|
|
|
|
// Widget imageBuilder({V2TimImage? originalImg, V2TimImage? smallImg}) {
|
|
// if (originalImg == null) {
|
|
// // 有path
|
|
// if (widget.message.imageElem!.path!.isNotEmpty &&
|
|
// File(widget.message.imageElem!.path!).existsSync()) {
|
|
// return getImage(
|
|
// GestureDetector(
|
|
// onTap: () {
|
|
// Get.to(ImagePreviewPage(
|
|
// type: IMG_PREVIEW_TYPE.local,
|
|
// path: widget.message.imageElem!.path!,
|
|
// ));
|
|
// },
|
|
// child: Image.file(
|
|
// File(widget.message.imageElem!.path!),
|
|
// fit: BoxFit.fitWidth,
|
|
// ),
|
|
// ),
|
|
// imageElem: null,
|
|
// );
|
|
// } else {
|
|
// return errorDisplay();
|
|
// }
|
|
// } else if (!Platform.isAndroid &&
|
|
// widget.message.imageElem!.path!.isNotEmpty &&
|
|
// File(widget.message.imageElem!.path!).existsSync() &&
|
|
// !imageIsRender) {
|
|
// return getImage(
|
|
// GestureDetector(
|
|
// onTap: () {
|
|
// Get.to(ImagePreviewPage(
|
|
// type: IMG_PREVIEW_TYPE.local,
|
|
// path: widget.message.imageElem!.path!,
|
|
// ));
|
|
// },
|
|
// child: Image.file(
|
|
// File(widget.message.imageElem!.path!),
|
|
// fit: BoxFit.fitWidth,
|
|
// ),
|
|
// ),
|
|
// imageElem: e,
|
|
// );
|
|
// } else if ((smallImg?.url ?? originalImg.url) != null && !imageIsRender) {
|
|
// double positionRadio = 1.0;
|
|
// if (smallImg?.width != null &&
|
|
// smallImg?.height != null &&
|
|
// smallImg?.width != 0 &&
|
|
// smallImg?.height != 0) {
|
|
// positionRadio = (smallImg!.width! / smallImg.height!);
|
|
// }
|
|
// String bigImgUrl = originalImg.url ?? getBigPicUrl();
|
|
// if (bigImgUrl.isEmpty && smallImg?.url != null) {
|
|
// bigImgUrl = smallImg!.url!;
|
|
// }
|
|
// return Stack(
|
|
// alignment: AlignmentDirectional.topStart,
|
|
// children: [
|
|
// AspectRatio(
|
|
// aspectRatio: positionRadio,
|
|
// child: Container(
|
|
// decoration: const BoxDecoration(color: Colors.white),
|
|
// ),
|
|
// ),
|
|
// getImage(
|
|
// GestureDetector(
|
|
// onTap: () {
|
|
// Get.to(ImagePreviewPage(
|
|
// type: IMG_PREVIEW_TYPE.url,
|
|
// path: smallImg?.url ?? originalImg.url!,
|
|
// ));
|
|
// },
|
|
// child: CachedNetworkImage(
|
|
// alignment: Alignment.topCenter,
|
|
// imageUrl: smallImg?.url ?? originalImg.url!,
|
|
// errorWidget: (context, error, stackTrace) => errorDisplay(),
|
|
// fit: BoxFit.fitWidth,
|
|
// cacheKey: smallImg?.uuid ?? originalImg.uuid!,
|
|
// placeholder: (context, url) =>
|
|
// Image(image: MemoryImage(kTransparentImage)),
|
|
// fadeInDuration: const Duration(milliseconds: 0),
|
|
// ),
|
|
// ),
|
|
// imageElem: e,
|
|
// ),
|
|
// ],
|
|
// );
|
|
// } else {
|
|
// // 有path
|
|
// if (widget.message.imageElem!.path!.isNotEmpty &&
|
|
// File(widget.message.imageElem!.path!).existsSync()) {
|
|
// return getImage(
|
|
// GestureDetector(
|
|
// onTap: () {
|
|
// Get.to(ImagePreviewPage(
|
|
// type: IMG_PREVIEW_TYPE.local,
|
|
// path: widget.message.imageElem!.path!,
|
|
// ));
|
|
// },
|
|
// child: Image.file(
|
|
// File(widget.message.imageElem!.path!),
|
|
// fit: BoxFit.fitWidth,
|
|
// ),
|
|
// ),
|
|
// imageElem: null,
|
|
// );
|
|
// } else {
|
|
// return errorDisplay();
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// Widget errorDisplay() {
|
|
// return Container(
|
|
// decoration: BoxDecoration(
|
|
// borderRadius: const BorderRadius.all(Radius.circular(5)),
|
|
// border: Border.all(
|
|
// width: 1,
|
|
// color: Colors.black12,
|
|
// ),
|
|
// ),
|
|
// height: 100,
|
|
// child: Center(
|
|
// child: Row(
|
|
// mainAxisAlignment: MainAxisAlignment.center,
|
|
// children: const [
|
|
// Icon(
|
|
// Icons.warning_amber_outlined,
|
|
// size: 16,
|
|
// ),
|
|
// Text(
|
|
// '图片加载失败',
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// ),
|
|
// );
|
|
// }
|
|
|
|
// void pushToPreview(List<String> mediaList) {
|
|
// Get.dialog(
|
|
// MomentMediaPreview(
|
|
// mediaSourceList: mediaList,
|
|
// initialPage: 0,
|
|
// ),
|
|
// useSafeArea: false,
|
|
// );
|
|
// }
|
|
|
|
// Widget getImage(image, {imageElem}) {
|
|
// Widget res = ClipRRect(
|
|
// clipper: ImageClipper(),
|
|
// child: image,
|
|
// );
|
|
// return res;
|
|
// }
|
|
|
|
// V2TimImage? getImageFromList(V2_TIM_IMAGE_TYPES_ENUM imgType) {
|
|
// V2TimImage? img = getImageFromImgList(
|
|
// widget.message.imageElem!.imageList,
|
|
// HistoryMessageDartConstant.imgPriorMap[imgType] ??
|
|
// HistoryMessageDartConstant.oriImgPrior,
|
|
// );
|
|
// return img;
|
|
// }
|
|
|
|
// String getBigPicUrl() {
|
|
// // 实际拿的是原图
|
|
// V2TimImage? img = getImageFromImgList(
|
|
// widget.message.imageElem!.imageList,
|
|
// HistoryMessageDartConstant.oriImgPrior,
|
|
// );
|
|
// if (img == null) {
|
|
// setState(() {
|
|
// imageIsRender = true;
|
|
// });
|
|
// }
|
|
// return img == null ? widget.message.imageElem!.path! : img.url!;
|
|
// }
|
|
|
|
// V2TimImage? getImageFromImgList(List<V2TimImage?>? list, List<String> order) {
|
|
// V2TimImage? img;
|
|
// try {
|
|
// for (String type in order) {
|
|
// img = list?.firstWhere(
|
|
// (e) => e?.type == HistoryMessageDartConstant.V2_TIM_IMAGE_TYPES[type],
|
|
// orElse: () => null,
|
|
// );
|
|
// }
|
|
// } catch (e) {
|
|
// UiTools.toast('getImageFromImgList error ${e.toString()}');
|
|
// }
|
|
// return img;
|
|
// }
|
|
// }
|
|
|
|
// class ImageClipper extends CustomClipper<RRect> {
|
|
// @override
|
|
// RRect getClip(Size size) {
|
|
// return RRect.fromRectAndRadius(
|
|
// Rect.fromLTWH(
|
|
// 0,
|
|
// 0,
|
|
// size.width,
|
|
// min(size.height, 256),
|
|
// ),
|
|
// const Radius.circular(5),
|
|
// );
|
|
// }
|
|
|
|
// @override
|
|
// bool shouldReclip(CustomClipper<RRect> oldClipper) {
|
|
// return oldClipper != this;
|
|
// }
|
|
// }
|