引入image_gallery_saver插件
pubspec.yaml文件中引入:
dependencies:
image_gallery_saver: ^1.1.0
权限设置
- Android配置
- 文件地址:android/app/src/profile/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.zetc.zetc_app"> <!-- Flutter needs it to communicate with the running application to allow setting breakpoints, to provide hot reload, etc. --> <uses-permission android:name="android.permission.INTERNET"/> <!--开启读写storage权限--> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> </manifest> - 文件地址:android/app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.zetc.zetc_app"> <uses-permission android:name="android.permission.INTERNET"/> <!--开启读写storage权限--> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <!-- io.flutter.app.FlutterApplication is an android.app.Application that calls FlutterMain.startInitialization(this); in its onCreate method. In most cases you can leave this as-is, but you if you want to provide additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. --> <application android:name="io.flutter.app.FlutterApplication" android:label="zetc_app" android:icon="@mipmap/ic_launcher"> <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> <!-- This keeps the window background of the activity showing until Flutter renders its first frame. It can be removed if there is no splash screen (such as the default splash screen defined in @style/LaunchTheme). --> <meta-data android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" android:value="true" /> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>
- 文件地址:android/app/src/profile/AndroidManifest.xml
- IOS配置
作用及使用
保存图片到手机
- 参考网址:image_gallery_saver
-
使用方式:
import 'package:image_gallery_saver/image_gallery_saver.dart'; import 'package:flutter/services.dart' show rootBundle; import 'dart:typed_data'; _saveImg () async { // print(qrcodeData); ByteData bytes = await rootBundle.load("assets/images/weixin.jpg"); final result = await ImageGallerySaver.save(bytes.buffer.asUint8List()); //这个是核心的保存图片的插件 if(result){ ToastUtil.showMsg('保存成功'); }else{ ToastUtil.showMsg('保存失败'); } }
欢迎加群讨论更多flutter相关问题(7天有效)如果失效,可加个人微信拉群


本文介绍了如何在Flutter应用中使用image_gallery_saver插件将图片保存到本地。首先,在pubspec.yaml文件中引入插件,然后配置Android和iOS的权限。在Android的AndroidManifest.xml文件中进行相应设置。接着,通过调用插件的方法,可以轻松将图片保存到手机相册。此外,还提供了相关讨论群和资源链接以获取更多信息。
2316

被折叠的 条评论
为什么被折叠?



