|
...
|
...
|
@@ -7,6 +7,7 @@ import 'package:common_utils/common_utils.dart'; |
|
|
|
import 'package:connectivity/connectivity.dart';
|
|
|
|
// import 'package:connectivity_plus/connectivity_plus.dart';
|
|
|
|
import 'package:device_info/device_info.dart';
|
|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
|
|
...
|
...
|
@@ -26,10 +27,12 @@ import 'package:permission_handler/permission_handler.dart'; |
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
import 'package:crypto/crypto.dart';
|
|
|
|
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
|
|
|
|
import '../app.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
|
|
|
|
typedef BookTimeSetCallback = void Function(bool needChange);
|
|
|
|
|
|
...
|
...
|
@@ -1163,16 +1166,18 @@ class Utils { |
|
|
|
String _userName = "gh_487873d353b3";
|
|
|
|
String _path = "pack-cookbook/pages/index?rid=$rid&identity=2&sid=$sid";
|
|
|
|
String _description = "OneKey";
|
|
|
|
Uint8List source = await testComporessList(_thumbnail);
|
|
|
|
var model = new WeChatShareMiniProgramModel(
|
|
|
|
webPageUrl: _webPageUrl,
|
|
|
|
userName: _userName,
|
|
|
|
title: _title,
|
|
|
|
path: _path,
|
|
|
|
// thumbnail: WeChatImage.asset(Utils.getImgPath('mini_image')),
|
|
|
|
description: _description,
|
|
|
|
|
|
|
|
thumbnail: WeChatImage.network(_thumbnail)
|
|
|
|
);
|
|
|
|
webPageUrl: _webPageUrl,
|
|
|
|
userName: _userName,
|
|
|
|
title: _title,
|
|
|
|
path: _path,
|
|
|
|
// thumbnail: WeChatImage.asset(Utils.getImgPath('mini_image')),
|
|
|
|
description: _description,
|
|
|
|
thumbnail: WeChatImage.binary(source)
|
|
|
|
|
|
|
|
// thumbnail: WeChatImage.network(_thumbnail)
|
|
|
|
);
|
|
|
|
bool isShare = await shareToWeChat(model);
|
|
|
|
print(isShare);
|
|
|
|
Loading.hideLoading(context);
|
|
...
|
...
|
@@ -1195,13 +1200,14 @@ class Utils { |
|
|
|
String _path =
|
|
|
|
"pack-cookbook/pages/success?rid=$rid&identity=2&hasOnlyShow=1";
|
|
|
|
String _description = "OneKey";
|
|
|
|
Uint8List source = await testComporessList(_thumbnail);
|
|
|
|
var model = new WeChatShareMiniProgramModel(
|
|
|
|
webPageUrl: _webPageUrl,
|
|
|
|
userName: _userName,
|
|
|
|
title: _title,
|
|
|
|
path: _path,
|
|
|
|
description: _description,
|
|
|
|
thumbnail: WeChatImage.network(_thumbnail));
|
|
|
|
thumbnail: WeChatImage.binary(source));
|
|
|
|
bool isShare = await shareToWeChat(model);
|
|
|
|
print(isShare);
|
|
|
|
Loading.hideLoading(context);
|
|
...
|
...
|
@@ -1252,6 +1258,57 @@ class Utils { |
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 下载图片
|
|
|
|
static downloadFile(String url) async {
|
|
|
|
// if (await Permission.storage.request().isGranted) {
|
|
|
|
var response = await Dio()
|
|
|
|
.get(url, options: Options(responseType: ResponseType.bytes));
|
|
|
|
Uint8List result = Uint8List.fromList(response.data);
|
|
|
|
return result;
|
|
|
|
// print(result);
|
|
|
|
// if (result["isSuccess"]) {
|
|
|
|
// showToast("下载成功");
|
|
|
|
// } else {
|
|
|
|
// showToast("下载失败");
|
|
|
|
// }
|
|
|
|
// }else{
|
|
|
|
// showToast("未获取存储权限");
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 图片压缩 Uint8List -> Uint8List
|
|
|
|
static Future<Uint8List> testComporessList(String url) async {
|
|
|
|
Uint8List result = await downloadFile(url);
|
|
|
|
if (result.length < 200 * 1024) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
var quality = 100;
|
|
|
|
if (result.length > 4 * 1024 * 1024) {
|
|
|
|
quality = 50;
|
|
|
|
} else if (result.length > 2 * 1024 * 1024) {
|
|
|
|
quality = 60;
|
|
|
|
} else if (result.length > 1 * 1024 * 1024) {
|
|
|
|
quality = 70;
|
|
|
|
} else if (result.length > 0.5 * 1024 * 1024) {
|
|
|
|
quality = 80;
|
|
|
|
} else if (result.length > 0.25 * 1024 * 1024) {
|
|
|
|
quality = 90;
|
|
|
|
}
|
|
|
|
|
|
|
|
var resizeBytes = await FlutterImageCompress.compressWithList(
|
|
|
|
result,
|
|
|
|
minHeight: 500,
|
|
|
|
minWidth: 400,
|
|
|
|
quality: quality,
|
|
|
|
// rotate: 135,
|
|
|
|
);
|
|
|
|
|
|
|
|
print("压缩前:${result.length / 1024}");
|
|
|
|
print("压缩后:${resizeBytes.length / 1024}");
|
|
|
|
|
|
|
|
return resizeBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
//分享邀请函
|
|
|
|
static goShareInvicationToWeChat(
|
|
|
|
BuildContext context, String rid, String uid) async {
|
|
...
|
...
|
@@ -1271,6 +1328,7 @@ class Utils { |
|
|
|
String _path =
|
|
|
|
"pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
|
|
|
|
String _description = "进入查看包间详情,转发同行好友,还可一键导航到饭店";
|
|
|
|
Uint8List source = await testComporessList(_thumbnail);
|
|
|
|
//跳转小程序
|
|
|
|
var model = new WeChatShareMiniProgramModel(
|
|
|
|
webPageUrl: _webPageUrl,
|
|
...
|
...
|
@@ -1278,7 +1336,8 @@ class Utils { |
|
|
|
title: _title,
|
|
|
|
path: _path,
|
|
|
|
description: _description,
|
|
|
|
thumbnail: WeChatImage.network(_thumbnail)
|
|
|
|
thumbnail: WeChatImage.binary(source)
|
|
|
|
// thumbnail: WeChatImage.network(_thumbnail)
|
|
|
|
// thumbnail: WeChatImage.binary(image)
|
|
|
|
);
|
|
|
|
//分享链接
|
...
|
...
|
|