feat: save image to photolib

This commit is contained in:
louis 2024-03-26 17:03:27 +08:00
parent 845c37e253
commit 74c9831ec7
4 changed files with 43 additions and 15 deletions

View File

@ -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

View File

@ -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']);
} }
} }

View File

@ -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 {

View File

@ -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),
),
))
], ],
), ),
); );