feat: save image to photolib
This commit is contained in:
parent
845c37e253
commit
74c9831ec7
|
@ -10,6 +10,7 @@
|
||||||
android:theme="@style/LaunchTheme"
|
android:theme="@style/LaunchTheme"
|
||||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
|
android:requestLegacyExternalStorage="true"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize">
|
||||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||||
the Android process has started. This theme is visible to the user
|
the Android process has started. This theme is visible to the user
|
||||||
|
|
|
@ -14,7 +14,7 @@ class DioService extends Get.GetxService {
|
||||||
static DioService get to => Get.Get.find();
|
static DioService get to => Get.Get.find();
|
||||||
static Dio get dio => _dio;
|
static Dio get dio => _dio;
|
||||||
static late Dio _dio;
|
static late Dio _dio;
|
||||||
List<String> whiteList = [Urls.login];
|
List<String> whiteList = [Urls.login, Urls.uploadAttachemnt];
|
||||||
BaseOptions dioBaseOptions = BaseOptions(
|
BaseOptions dioBaseOptions = BaseOptions(
|
||||||
connectTimeout: const Duration(seconds: 20),
|
connectTimeout: const Duration(seconds: 20),
|
||||||
baseUrl: '${GloablConfig.BASE_URL}',
|
baseUrl: '${GloablConfig.BASE_URL}',
|
||||||
|
@ -131,18 +131,17 @@ class DioService extends Get.GetxService {
|
||||||
handler.next(response);
|
handler.next(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (response.data != null) {
|
if (response.data != null && response.data is Map) {
|
||||||
if (response.data['code'] == 200) {
|
if (response.data['code'] == 200) {
|
||||||
if (GloablConfig.DEBUG) LoggerUtil().info(response.data['data']);
|
if (GloablConfig.DEBUG) LoggerUtil().info(response.data['data']);
|
||||||
response.data = response.data['data'];
|
response.data = response.data['data'];
|
||||||
// 分页数据处理
|
// 分页数据处理
|
||||||
if (response.data != null &&
|
if (response.data != null &&
|
||||||
response.data is Map &&
|
|
||||||
response.data['meta'] != null &&
|
response.data['meta'] != null &&
|
||||||
response.data['items'] != null) {
|
response.data['items'] != null) {
|
||||||
response.data = PaginationData.fromJson(response.data);
|
response.data = PaginationData.fromJson(response.data);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (response.data['message'] != null) {
|
||||||
await SnackBarUtil().error(response.data['message']);
|
await SnackBarUtil().error(response.data['message']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'dart:typed_data';
|
||||||
import 'package:dio/dio.dart' as Dio;
|
import 'package:dio/dio.dart' as Dio;
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
||||||
import 'package:sk_base_mobile/apis/index.dart';
|
import 'package:sk_base_mobile/apis/index.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
import 'package:sk_base_mobile/models/upload_result.model.dart';
|
import 'package:sk_base_mobile/models/upload_result.model.dart';
|
||||||
|
@ -69,16 +72,15 @@ class MediaUtil {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// // 保存到相册
|
// 保存到相册
|
||||||
// Future saveImageToPhotoLib({required String imgUrl, String? filename}) async {
|
Future saveImageToPhotoLib({required String imgUrl, String? filename}) async {
|
||||||
// // ?? "http://qiniu-app.hua10.com/20190815155000_256512.png"
|
var response = await DioService.dio
|
||||||
// var response = await Dio()
|
.get(imgUrl, options: Options(responseType: ResponseType.bytes));
|
||||||
// .get(imgUrl, options: Options(responseType: ResponseType.bytes));
|
final result = await ImageGallerySaver.saveImage(
|
||||||
// final result = await ImageGallerySaver.saveImage(
|
Uint8List.fromList(response.data),
|
||||||
// Uint8List.fromList(response.data),
|
quality: 60);
|
||||||
// quality: 60);
|
return result;
|
||||||
// return result;
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// ///选取视频
|
// ///选取视频
|
||||||
// Future<XFile?> getVideoFromGallery() async {
|
// Future<XFile?> getVideoFromGallery() async {
|
||||||
|
|
|
@ -2,9 +2,13 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:photo_view/photo_view.dart';
|
import 'package:photo_view/photo_view.dart';
|
||||||
import 'package:photo_view/photo_view_gallery.dart';
|
import 'package:photo_view/photo_view_gallery.dart';
|
||||||
|
import 'package:sk_base_mobile/app_theme.dart';
|
||||||
import 'package:sk_base_mobile/config.dart';
|
import 'package:sk_base_mobile/config.dart';
|
||||||
import 'package:sk_base_mobile/models/file.model.dart';
|
import 'package:sk_base_mobile/models/file.model.dart';
|
||||||
|
import 'package:sk_base_mobile/util/loading_util.dart';
|
||||||
|
import 'package:sk_base_mobile/util/media_util.dart';
|
||||||
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
|
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
|
||||||
|
import 'package:sk_base_mobile/util/snack_bar.util.dart';
|
||||||
import 'package:sk_base_mobile/widgets/fade_in_cache_image.dart';
|
import 'package:sk_base_mobile/widgets/fade_in_cache_image.dart';
|
||||||
import 'package:sk_base_mobile/widgets/loading_indicator.dart';
|
import 'package:sk_base_mobile/widgets/loading_indicator.dart';
|
||||||
|
|
||||||
|
@ -61,7 +65,29 @@ class _ImagePreivewState extends State<ImagePreivew> {
|
||||||
fontSize: ScreenAdaper.sp(20),
|
fontSize: ScreenAdaper.sp(20),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
|
Positioned(
|
||||||
|
top: ScreenAdaper.height(10),
|
||||||
|
right: ScreenAdaper.width(10),
|
||||||
|
child: IconButton(
|
||||||
|
onPressed: () async {
|
||||||
|
try {
|
||||||
|
LoadingUtil.to.show();
|
||||||
|
await MediaUtil().saveImageToPhotoLib(
|
||||||
|
imgUrl:
|
||||||
|
'${GloablConfig.OSS_URL}${widget.galleryItems[currentIndex].path}');
|
||||||
|
} catch (e) {
|
||||||
|
} finally {
|
||||||
|
LoadingUtil.to.dismiss();
|
||||||
|
SnackBarUtil().success('已保存到相册');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
icon: Icon(
|
||||||
|
Icons.download_for_offline_sharp,
|
||||||
|
color: AppTheme.nearlyWhite,
|
||||||
|
size: ScreenAdaper.sp(50),
|
||||||
|
),
|
||||||
|
))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue