Skip to content

Commit 7199c0b

Browse files
author
师春雷
committed
升级第三方插件
1 parent 332326e commit 7199c0b

File tree

6 files changed

+197
-47
lines changed

6 files changed

+197
-47
lines changed

lib/page/mine_page.dart

+30-4
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,37 @@ class _MinePageState extends State<MinePage> {
196196
Future<Null> _cropImage(File imageFile) async {
197197
assert(imageFile != null);
198198
File croppedFile = await ImageCropper.cropImage(
199+
/// 图像文件的绝对路径。
199200
sourcePath: imageFile.path,
200-
ratioX: 1.0,
201-
ratioY: 1.0,
202-
maxWidth: 512,
203-
maxHeight: 512,
201+
202+
/// 最大裁剪的图像宽度
203+
maxWidth: 256,
204+
205+
/// 最大裁剪的图像高度
206+
maxHeight: 256,
207+
208+
/// 控制裁剪菜单视图中纵横比的列表。在Android中,您可以通过设置的值来设置启动裁切器时的初始化纵横比AndroidUiSettings.initAspectRatio
209+
aspectRatioPresets: [CropAspectRatioPreset.square],
210+
211+
/// 控制裁剪边界的样式,可以是矩形或圆形样式
212+
cropStyle: CropStyle.circle,
213+
214+
/// 结果图像的格式,png或jpg
215+
compressFormat: ImageCompressFormat.jpg,
216+
217+
/// 用于控制图像压缩的质量,取值范围[1-100]
218+
compressQuality: 100,
219+
androidUiSettings: AndroidUiSettings(
220+
toolbarTitle: "裁剪",
221+
toolbarColor: Theme.of(context).accentColor,
222+
statusBarColor: Theme.of(context).accentColor,
223+
toolbarWidgetColor: Colors.white,
224+
),
225+
iosUiSettings: IOSUiSettings(
226+
minimumAspectRatio: 1.0,
227+
doneButtonTitle: S.of(context).sure,
228+
cancelButtonTitle: S.of(context).cancel,
229+
),
204230
);
205231

206232
debugPrint('cropImage=============${croppedFile.path}');

lib/service/api_service.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:html/parser.dart' show parse;
99

1010
import '../page_index.dart';
1111

12-
class ApiService<T> {
12+
class ApiService {
1313
/// 豆瓣电影首页数据
1414
static Future<MovieHomeData> getMovieHomeData({String city}) async {
1515
Response response =

lib/utils/file_util.dart

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ class FileUtil {
1515

1616
FileUtil._internal();
1717

18+
Future<String> getTempPath() async {
19+
Directory tempDir = await getTemporaryDirectory();
20+
String path = tempDir.path;
21+
return path;
22+
}
23+
1824
Future<String> getFolderPath(String folderPath) async {
1925
Directory tempDir = await getApplicationDocumentsDirectory();
2026
String path = tempDir.path + folderPath;

lib/utils/http_utils.dart

+129-11
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
1+
import 'dart:convert';
12
import 'dart:io';
23

34
import 'package:cookie_jar/cookie_jar.dart';
45
import 'package:dio/dio.dart';
56
import 'package:flutter/material.dart';
6-
import 'package:flutter_app/global/config.dart';
7-
import 'package:flutter_app/service/api_url.dart';
7+
8+
import '../page_index.dart';
89

910
class HttpUtils {
1011
/// http request methods
1112
static const String GET = 'get';
1213
static const String POST = 'post';
13-
static const String PUT = 'put';
14-
static const String PATCH = 'patch';
15-
static const String DELETE = 'delete';
1614

1715
Dio _dio;
18-
BaseOptions options;
1916

2017
CancelToken cancelToken = CancelToken();
2118

2219
Dio get dio => _dio;
2320

24-
static const CONTENT_TYPE_JSON = "application/json";
25-
static const CONTENT_TYPE_FORM = "application/x-www-form-urlencoded";
26-
2721
HttpUtils({String baseUrl: ApiUrl.BASE_URL}) {
2822
debugPrint('dio赋值=====$baseUrl');
2923

@@ -42,8 +36,9 @@ class HttpUtils {
4236
responseType: ResponseType.plain,
4337

4438
/// 请求的Content-Type,默认值是[ContentType.json]. 也可以用ContentType.parse("application/x-www-form-urlencoded")
45-
contentType:
46-
ContentType('application', CONTENT_TYPE_FORM, charset: 'utf-8'),
39+
contentType: ContentType(
40+
'application', 'application/x-www-form-urlencoded',
41+
charset: 'utf-8'),
4742

4843
/// Http请求头.
4944
headers: {
@@ -219,4 +214,127 @@ class HttpUtils {
219214
void cancelRequests(CancelToken token) {
220215
token.cancel("cancelled");
221216
}
217+
218+
get(
219+
String path,
220+
Function successCallBack, {
221+
Map<String, dynamic> params,
222+
CancelToken cancelToken,
223+
Options options,
224+
Function errorCallBack,
225+
}) async {
226+
_requestHttp(path, successCallBack,
227+
method: GET,
228+
params: params,
229+
errorCallBack: errorCallBack,
230+
options: options,
231+
cancelToken: cancelToken);
232+
}
233+
234+
post(
235+
String path,
236+
Function successCallBack, {
237+
Map<String, dynamic> params,
238+
CancelToken cancelToken,
239+
Options options,
240+
Function errorCallBack,
241+
}) async {
242+
_requestHttp(path, successCallBack,
243+
method: POST,
244+
params: params,
245+
errorCallBack: errorCallBack,
246+
options: options,
247+
cancelToken: cancelToken);
248+
}
249+
250+
_requestHttp(
251+
String path,
252+
Function successCallBack, {
253+
String method,
254+
Map<String, dynamic> params,
255+
Function errorCallBack,
256+
CancelToken cancelToken,
257+
Options options,
258+
}) async {
259+
Response response;
260+
try {
261+
if (method == GET) {
262+
if (params != null && params.isNotEmpty) {
263+
response = await dio.get(path,
264+
queryParameters: params,
265+
options: _checkOptions(method, options),
266+
cancelToken: cancelToken);
267+
} else {
268+
response = await dio.get(path,
269+
options: _checkOptions(method, options),
270+
cancelToken: cancelToken);
271+
}
272+
} else if (method == POST) {
273+
if (params != null && params.isNotEmpty) {
274+
response = await dio
275+
.post(path, data: params, options: _checkOptions(method, options),
276+
onReceiveProgress: (int count, int total) {
277+
debugPrint(
278+
'onReceiveProgress: ${(count / total * 100).toStringAsFixed(0)} %');
279+
}, onSendProgress: (int count, int total) {
280+
debugPrint(
281+
'onSendProgress: ${(count / total * 100).toStringAsFixed(0)} %');
282+
}, cancelToken: cancelToken);
283+
} else {
284+
response = await dio
285+
.post(path, options: _checkOptions(method, options),
286+
onReceiveProgress: (int count, int total) {
287+
debugPrint(
288+
'onReceiveProgress: ${(count / total * 100).toStringAsFixed(0)} %');
289+
}, onSendProgress: (int count, int total) {
290+
debugPrint(
291+
'onSendProgress: ${(count / total * 100).toStringAsFixed(0)} %');
292+
}, cancelToken: cancelToken);
293+
}
294+
}
295+
296+
/// debug模式才打印
297+
if (Config.DEBUG) {
298+
/// 响应数据,可能已经被转换了类型, 详情请参考Options中的[ResponseType].
299+
debugPrint('$method请求成功!response.data:${response.data}');
300+
301+
/// 响应头
302+
debugPrint('$method请求成功!response.headers:${response.headers}');
303+
304+
/// 本次请求信息
305+
debugPrint('$method请求成功!response.request:${response.request}');
306+
307+
/// Http status code.
308+
debugPrint('$method请求成功!response.statusCode:${response.statusCode}');
309+
}
310+
} on DioError catch (error) {
311+
// 请求错误处理
312+
debugPrint(error.response.toString());
313+
formatError(error);
314+
315+
// debug模式才打印
316+
if (Config.DEBUG) {
317+
debugPrint('请求异常: ' + error.toString());
318+
debugPrint('请求异常url: ' + path);
319+
debugPrint('请求头: ' + dio.options.headers.toString());
320+
debugPrint('method: ' + dio.options.method);
321+
}
322+
_error(errorCallBack, error.message);
323+
return '';
324+
}
325+
String dataStr = json.encode(response.data);
326+
Map<String, dynamic> dataMap = json.decode(dataStr);
327+
if (dataMap == null || dataMap['code'] == 0) {
328+
_error(errorCallBack,
329+
'错误码:' + dataMap['code'].toString() + dataMap['message'].toString());
330+
} else if (successCallBack != null) {
331+
successCallBack(dataMap);
332+
}
333+
}
334+
335+
_error(Function errorCallBack, String error) {
336+
if (errorCallBack != null) {
337+
errorCallBack(error);
338+
}
339+
}
222340
}

pubspec.lock

+18-18
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,21 @@ packages:
7777
name: charts_common
7878
url: "https://pub.flutter-io.cn"
7979
source: hosted
80-
version: "0.8.0"
80+
version: "0.8.1"
8181
charts_flutter:
8282
dependency: "direct main"
8383
description:
8484
name: charts_flutter
8585
url: "https://pub.flutter-io.cn"
8686
source: hosted
87-
version: "0.8.0"
87+
version: "0.8.1"
8888
chewie:
8989
dependency: "direct main"
9090
description:
9191
name: chewie
9292
url: "https://pub.flutter-io.cn"
9393
source: hosted
94-
version: "0.9.7"
94+
version: "0.9.8+1"
9595
city_picker:
9696
dependency: "direct main"
9797
description:
@@ -105,7 +105,7 @@ packages:
105105
name: city_pickers
106106
url: "https://pub.flutter-io.cn"
107107
source: hosted
108-
version: "0.1.25"
108+
version: "0.1.27"
109109
clippy_flutter:
110110
dependency: "direct main"
111111
description:
@@ -175,7 +175,7 @@ packages:
175175
name: device_info
176176
url: "https://pub.flutter-io.cn"
177177
source: hosted
178-
version: "0.4.0+2"
178+
version: "0.4.0+3"
179179
dio:
180180
dependency: "direct main"
181181
description:
@@ -202,7 +202,7 @@ packages:
202202
description:
203203
path: "."
204204
ref: HEAD
205-
resolved-ref: "1195ba57f144ab7ad23cc8b054f8153096b5ee60"
205+
resolved-ref: "375653ba14bc7bb20c137c8b422c4c1dfdce7400"
206206
url: "https://github.com/iampawan/Flute-Music-Player"
207207
source: git
208208
version: "0.0.6"
@@ -266,7 +266,7 @@ packages:
266266
name: flutter_sound
267267
url: "https://pub.flutter-io.cn"
268268
source: hosted
269-
version: "1.4.5"
269+
version: "1.4.8"
270270
flutter_spinkit:
271271
dependency: "direct main"
272272
description:
@@ -313,7 +313,7 @@ packages:
313313
name: html
314314
url: "https://pub.flutter-io.cn"
315315
source: hosted
316-
version: "0.14.0+2"
316+
version: "0.14.0+3"
317317
http:
318318
dependency: "direct main"
319319
description:
@@ -334,14 +334,14 @@ packages:
334334
name: image_cropper
335335
url: "https://pub.flutter-io.cn"
336336
source: hosted
337-
version: "1.0.2"
337+
version: "1.1.0"
338338
image_picker:
339339
dependency: "direct main"
340340
description:
341341
name: image_picker
342342
url: "https://pub.flutter-io.cn"
343343
source: hosted
344-
version: "0.6.1+4"
344+
version: "0.6.1+7"
345345
image_picker_saver:
346346
dependency: "direct main"
347347
description:
@@ -404,7 +404,7 @@ packages:
404404
name: multi_image_picker
405405
url: "https://pub.flutter-io.cn"
406406
source: hosted
407-
version: "4.5.5"
407+
version: "4.5.8"
408408
open_iconic_flutter:
409409
dependency: transitive
410410
description:
@@ -530,7 +530,7 @@ packages:
530530
name: rxdart
531531
url: "https://pub.flutter-io.cn"
532532
source: hosted
533-
version: "0.22.2"
533+
version: "0.22.3"
534534
screen:
535535
dependency: transitive
536536
description:
@@ -544,7 +544,7 @@ packages:
544544
name: share
545545
url: "https://pub.flutter-io.cn"
546546
source: hosted
547-
version: "0.6.2+1"
547+
version: "0.6.2+3"
548548
shared_preferences:
549549
dependency: "direct main"
550550
description:
@@ -577,7 +577,7 @@ packages:
577577
name: sqflite
578578
url: "https://pub.flutter-io.cn"
579579
source: hosted
580-
version: "1.1.6+4"
580+
version: "1.1.7+1"
581581
stack_trace:
582582
dependency: transitive
583583
description:
@@ -654,7 +654,7 @@ packages:
654654
name: url_launcher
655655
url: "https://pub.flutter-io.cn"
656656
source: hosted
657-
version: "5.1.3"
657+
version: "5.1.6"
658658
uuid:
659659
dependency: transitive
660660
description:
@@ -675,7 +675,7 @@ packages:
675675
name: video_player
676676
url: "https://pub.flutter-io.cn"
677677
source: hosted
678-
version: "0.10.2+1"
678+
version: "0.10.2+3"
679679
sdks:
680-
dart: ">=2.3.0-dev.0.5.flutter-a1668566e5 <3.0.0"
681-
flutter: ">=1.7.8 <2.0.0"
680+
dart: ">=2.5.0 <3.0.0"
681+
flutter: ">=1.9.1 <2.0.0"

0 commit comments

Comments
 (0)