|
@@ -7,6 +7,7 @@ import 'package:common_utils/common_utils.dart'; |
|
@@ -7,6 +7,7 @@ import 'package:common_utils/common_utils.dart'; |
|
7
|
import 'package:connectivity/connectivity.dart';
|
7
|
import 'package:connectivity/connectivity.dart';
|
|
8
|
// import 'package:connectivity_plus/connectivity_plus.dart';
|
8
|
// import 'package:connectivity_plus/connectivity_plus.dart';
|
|
9
|
import 'package:device_info/device_info.dart';
|
9
|
import 'package:device_info/device_info.dart';
|
|
|
|
10
|
+import 'package:dio/dio.dart';
|
|
10
|
import 'package:flutter/cupertino.dart';
|
11
|
import 'package:flutter/cupertino.dart';
|
|
11
|
import 'package:flutter/material.dart';
|
12
|
import 'package:flutter/material.dart';
|
|
12
|
import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
|
13
|
import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
|
|
@@ -26,10 +27,12 @@ import 'package:permission_handler/permission_handler.dart'; |
|
@@ -26,10 +27,12 @@ import 'package:permission_handler/permission_handler.dart'; |
|
26
|
import 'package:provider/provider.dart';
|
27
|
import 'package:provider/provider.dart';
|
|
27
|
import 'package:url_launcher/url_launcher.dart';
|
28
|
import 'package:url_launcher/url_launcher.dart';
|
|
28
|
import 'package:crypto/crypto.dart';
|
29
|
import 'package:crypto/crypto.dart';
|
|
|
|
30
|
+import 'package:flutter_image_compress/flutter_image_compress.dart';
|
|
29
|
import 'dart:convert';
|
31
|
import 'dart:convert';
|
|
30
|
import 'package:webview_flutter/webview_flutter.dart';
|
32
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
31
|
|
33
|
|
|
32
|
import '../app.dart';
|
34
|
import '../app.dart';
|
|
|
|
35
|
+import 'package:http/http.dart' as http;
|
|
33
|
|
36
|
|
|
34
|
typedef BookTimeSetCallback = void Function(bool needChange);
|
37
|
typedef BookTimeSetCallback = void Function(bool needChange);
|
|
35
|
|
38
|
|
|
@@ -1163,16 +1166,18 @@ class Utils { |
|
@@ -1163,16 +1166,18 @@ class Utils { |
|
1163
|
String _userName = "gh_487873d353b3";
|
1166
|
String _userName = "gh_487873d353b3";
|
|
1164
|
String _path = "pack-cookbook/pages/index?rid=$rid&identity=2&sid=$sid";
|
1167
|
String _path = "pack-cookbook/pages/index?rid=$rid&identity=2&sid=$sid";
|
|
1165
|
String _description = "OneKey";
|
1168
|
String _description = "OneKey";
|
|
|
|
1169
|
+ Uint8List source = await testComporessList(_thumbnail);
|
|
1166
|
var model = new WeChatShareMiniProgramModel(
|
1170
|
var model = new WeChatShareMiniProgramModel(
|
|
1167
|
- webPageUrl: _webPageUrl,
|
|
|
|
1168
|
- userName: _userName,
|
|
|
|
1169
|
- title: _title,
|
|
|
|
1170
|
- path: _path,
|
|
|
|
1171
|
- // thumbnail: WeChatImage.asset(Utils.getImgPath('mini_image')),
|
|
|
|
1172
|
- description: _description,
|
|
|
|
1173
|
-
|
|
|
|
1174
|
- thumbnail: WeChatImage.network(_thumbnail)
|
|
|
|
1175
|
- );
|
1171
|
+ webPageUrl: _webPageUrl,
|
|
|
|
1172
|
+ userName: _userName,
|
|
|
|
1173
|
+ title: _title,
|
|
|
|
1174
|
+ path: _path,
|
|
|
|
1175
|
+ // thumbnail: WeChatImage.asset(Utils.getImgPath('mini_image')),
|
|
|
|
1176
|
+ description: _description,
|
|
|
|
1177
|
+ thumbnail: WeChatImage.binary(source)
|
|
|
|
1178
|
+
|
|
|
|
1179
|
+ // thumbnail: WeChatImage.network(_thumbnail)
|
|
|
|
1180
|
+ );
|
|
1176
|
bool isShare = await shareToWeChat(model);
|
1181
|
bool isShare = await shareToWeChat(model);
|
|
1177
|
print(isShare);
|
1182
|
print(isShare);
|
|
1178
|
Loading.hideLoading(context);
|
1183
|
Loading.hideLoading(context);
|
|
@@ -1195,13 +1200,14 @@ class Utils { |
|
@@ -1195,13 +1200,14 @@ class Utils { |
|
1195
|
String _path =
|
1200
|
String _path =
|
|
1196
|
"pack-cookbook/pages/success?rid=$rid&identity=2&hasOnlyShow=1";
|
1201
|
"pack-cookbook/pages/success?rid=$rid&identity=2&hasOnlyShow=1";
|
|
1197
|
String _description = "OneKey";
|
1202
|
String _description = "OneKey";
|
|
|
|
1203
|
+ Uint8List source = await testComporessList(_thumbnail);
|
|
1198
|
var model = new WeChatShareMiniProgramModel(
|
1204
|
var model = new WeChatShareMiniProgramModel(
|
|
1199
|
webPageUrl: _webPageUrl,
|
1205
|
webPageUrl: _webPageUrl,
|
|
1200
|
userName: _userName,
|
1206
|
userName: _userName,
|
|
1201
|
title: _title,
|
1207
|
title: _title,
|
|
1202
|
path: _path,
|
1208
|
path: _path,
|
|
1203
|
description: _description,
|
1209
|
description: _description,
|
|
1204
|
- thumbnail: WeChatImage.network(_thumbnail));
|
1210
|
+ thumbnail: WeChatImage.binary(source));
|
|
1205
|
bool isShare = await shareToWeChat(model);
|
1211
|
bool isShare = await shareToWeChat(model);
|
|
1206
|
print(isShare);
|
1212
|
print(isShare);
|
|
1207
|
Loading.hideLoading(context);
|
1213
|
Loading.hideLoading(context);
|
|
@@ -1252,6 +1258,57 @@ class Utils { |
|
@@ -1252,6 +1258,57 @@ class Utils { |
|
1252
|
return false;
|
1258
|
return false;
|
|
1253
|
}
|
1259
|
}
|
|
1254
|
|
1260
|
|
|
|
|
1261
|
+ /// 下载图片
|
|
|
|
1262
|
+ static downloadFile(String url) async {
|
|
|
|
1263
|
+ // if (await Permission.storage.request().isGranted) {
|
|
|
|
1264
|
+ var response = await Dio()
|
|
|
|
1265
|
+ .get(url, options: Options(responseType: ResponseType.bytes));
|
|
|
|
1266
|
+ Uint8List result = Uint8List.fromList(response.data);
|
|
|
|
1267
|
+ return result;
|
|
|
|
1268
|
+ // print(result);
|
|
|
|
1269
|
+ // if (result["isSuccess"]) {
|
|
|
|
1270
|
+ // showToast("下载成功");
|
|
|
|
1271
|
+ // } else {
|
|
|
|
1272
|
+ // showToast("下载失败");
|
|
|
|
1273
|
+ // }
|
|
|
|
1274
|
+ // }else{
|
|
|
|
1275
|
+ // showToast("未获取存储权限");
|
|
|
|
1276
|
+ // }
|
|
|
|
1277
|
+ }
|
|
|
|
1278
|
+
|
|
|
|
1279
|
+ /// 图片压缩 Uint8List -> Uint8List
|
|
|
|
1280
|
+ static Future<Uint8List> testComporessList(String url) async {
|
|
|
|
1281
|
+ Uint8List result = await downloadFile(url);
|
|
|
|
1282
|
+ if (result.length < 200 * 1024) {
|
|
|
|
1283
|
+ return result;
|
|
|
|
1284
|
+ }
|
|
|
|
1285
|
+ var quality = 100;
|
|
|
|
1286
|
+ if (result.length > 4 * 1024 * 1024) {
|
|
|
|
1287
|
+ quality = 50;
|
|
|
|
1288
|
+ } else if (result.length > 2 * 1024 * 1024) {
|
|
|
|
1289
|
+ quality = 60;
|
|
|
|
1290
|
+ } else if (result.length > 1 * 1024 * 1024) {
|
|
|
|
1291
|
+ quality = 70;
|
|
|
|
1292
|
+ } else if (result.length > 0.5 * 1024 * 1024) {
|
|
|
|
1293
|
+ quality = 80;
|
|
|
|
1294
|
+ } else if (result.length > 0.25 * 1024 * 1024) {
|
|
|
|
1295
|
+ quality = 90;
|
|
|
|
1296
|
+ }
|
|
|
|
1297
|
+
|
|
|
|
1298
|
+ var resizeBytes = await FlutterImageCompress.compressWithList(
|
|
|
|
1299
|
+ result,
|
|
|
|
1300
|
+ minHeight: 500,
|
|
|
|
1301
|
+ minWidth: 400,
|
|
|
|
1302
|
+ quality: quality,
|
|
|
|
1303
|
+ // rotate: 135,
|
|
|
|
1304
|
+ );
|
|
|
|
1305
|
+
|
|
|
|
1306
|
+ print("压缩前:${result.length / 1024}");
|
|
|
|
1307
|
+ print("压缩后:${resizeBytes.length / 1024}");
|
|
|
|
1308
|
+
|
|
|
|
1309
|
+ return resizeBytes;
|
|
|
|
1310
|
+ }
|
|
|
|
1311
|
+
|
|
1255
|
//分享邀请函
|
1312
|
//分享邀请函
|
|
1256
|
static goShareInvicationToWeChat(
|
1313
|
static goShareInvicationToWeChat(
|
|
1257
|
BuildContext context, String rid, String uid) async {
|
1314
|
BuildContext context, String rid, String uid) async {
|
|
@@ -1271,6 +1328,7 @@ class Utils { |
|
@@ -1271,6 +1328,7 @@ class Utils { |
|
1271
|
String _path =
|
1328
|
String _path =
|
|
1272
|
"pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
|
1329
|
"pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
|
|
1273
|
String _description = "进入查看包间详情,转发同行好友,还可一键导航到饭店";
|
1330
|
String _description = "进入查看包间详情,转发同行好友,还可一键导航到饭店";
|
|
|
|
1331
|
+ Uint8List source = await testComporessList(_thumbnail);
|
|
1274
|
//跳转小程序
|
1332
|
//跳转小程序
|
|
1275
|
var model = new WeChatShareMiniProgramModel(
|
1333
|
var model = new WeChatShareMiniProgramModel(
|
|
1276
|
webPageUrl: _webPageUrl,
|
1334
|
webPageUrl: _webPageUrl,
|
|
@@ -1278,7 +1336,8 @@ class Utils { |
|
@@ -1278,7 +1336,8 @@ class Utils { |
|
1278
|
title: _title,
|
1336
|
title: _title,
|
|
1279
|
path: _path,
|
1337
|
path: _path,
|
|
1280
|
description: _description,
|
1338
|
description: _description,
|
|
1281
|
- thumbnail: WeChatImage.network(_thumbnail)
|
1339
|
+ thumbnail: WeChatImage.binary(source)
|
|
|
|
1340
|
+ // thumbnail: WeChatImage.network(_thumbnail)
|
|
1282
|
// thumbnail: WeChatImage.binary(image)
|
1341
|
// thumbnail: WeChatImage.binary(image)
|
|
1283
|
);
|
1342
|
);
|
|
1284
|
//分享链接
|
1343
|
//分享链接
|