Browse Source

Merge remote-tracking branch 'origin/wr_202303' into wr_202303

wr_202303
wurong 4 months ago
parent
commit
1bcaf85c46
  1. 1
      lib/im/SocketClient.dart
  2. 20
      lib/im/chat_details_page.dart
  3. 7
      lib/im/im_view/im_page.dart
  4. 11
      lib/utils/qiniu.dart

1
lib/im/SocketClient.dart

@ -218,6 +218,7 @@ class SocketClient {
final proto2 = Proto(5, 1, msgData.writeToBuffer());
try {
_socket.add(proto2.toBytes());
debugPrint("socket-send-success:");
} catch (e) {
hxDatabase.update({"id": id, "state": 3}).catchError((error) {
debugPrint("insertMessage: ${error.toString()}");

20
lib/im/chat_details_page.dart

@ -290,6 +290,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
////
Future getImageOrVideo(GalleryMode galleryMode) async {
if (selectCount == 0) return;
mediaPaths.clear();
List<Media> medias = await ImagePickers.pickerPaths(
galleryMode: galleryMode,
selectCount: (galleryMode == GalleryMode.video) ? 1 : selectCount,
@ -1193,7 +1194,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
},
onTap:(){},
child: FutureBuilder(
future: fetchImageSize(messages[position].attach),
future: fetchImageSize(messages[position]),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.waiting || snapshot.hasError) {
return Image.file(
@ -1231,7 +1232,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
},
onTap:(){},
child: FutureBuilder(
future: fetchImageSize(messages[position].attach),
future: fetchImageSize(messages[position]),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.waiting || snapshot.hasError) {
return Image.file(
@ -1286,13 +1287,18 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
);
}
Future<Size> fetchImageSize(String imagePath) async {
debugPrint("$imagePath");
Future<Size> fetchImageSize(Message message) async {
String imageLocalPath = message.attach;
debugPrint("$imageLocalPath");
File file = File(imageLocalPath);
if (!(await file.exists())) {
await qiniu.downloadFile(message.content, savePath: imageLocalPath);
}
Size size = Size.zero;
Completer<Size> completer = Completer();
Image.file(
File(imagePath),
).image.resolve(ImageConfiguration())
Image.file(file).image.resolve(ImageConfiguration())
.addListener(ImageStreamListener((image, synchronousCall) {
size = Size((image.image.width ?? 0).toDouble(), (image.image.height ?? 0).toDouble());
size = resizeImage(size);

7
lib/im/im_view/im_page.dart

@ -700,7 +700,12 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
Widget messageItem(img, title, messageNum) {
return Container(
padding: EdgeInsets.only(top: 8.h, bottom: 8.h, left: 16.w, right: 15.w),
padding: EdgeInsets.only(
top: 8.h,
bottom: 8.h,
left: 16.w,
right: 15.w,
),
child: Column(
children: [
Row(

11
lib/utils/qiniu.dart

@ -64,11 +64,16 @@ class Qiniu {
}
}
Dio dio = Dio();
final Dio dio = Dio();
Future<String> downloadFile(String urlPath) async {
Future<String> downloadFile(String urlPath, {String savePath}) async {
Directory dir = await getTemporaryDirectory();
File newFile = File("${dir.path}/hx_${urlPath.split('/').last}");
File newFile;
if (savePath != null && savePath != '') {
newFile = File(savePath);
} else {
newFile = File("${dir.path}/hx_${urlPath.split('/').last}");
}
Response response = await dio.download(urlPath, newFile.path);
if (response.statusCode == 200) {
return newFile.path;

Loading…
Cancel
Save