0 purchases
x image picker
x_image_picker #
flutter 图片和视频选择器
iOS基于ZLPhotoBrowser
Android基于PictureSelector
灵感来源于images_picker
视频缩略图基于video_thumbnail
Android设置 #
修改最低SDK版本为19, 文件路径android/app/build.gradle
defaultConfig {
applicationId "com.huanshao.x_image_picker_example"
minSdkVersion 19 // here
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
copied to clipboard
添加依赖androidx.camera:camera-camera2
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.camera:camera-camera2:1.1.0-alpha06" // here
}
copied to clipboard
修改android/build.gradle中kotlin_version的版本为1.4.32
ext.kotlin_version = '1.4.32'
copied to clipboard
添加application类, 并在AndroidManifest.xml的application标签中声明
package com.huanshao.x_image_picker_example
import android.app.Application
import androidx.camera.camera2.Camera2Config
import androidx.camera.core.CameraXConfig
import io.flutter.app.FlutterApplication
class MyApplication: FlutterApplication(), CameraXConfig.Provider {
override fun onCreate() {
super.onCreate()
}
override fun getCameraXConfig(): CameraXConfig {
return Camera2Config.defaultConfig();
}
}
copied to clipboard
<application
android:label="x_image_picker_example"
android:icon="@mipmap/ic_launcher"
android:name=".MyApplication"
>
.......
</application>
copied to clipboard
添加权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
copied to clipboard
IOS设置 #
添加权限描述
<key>NSCameraUsageDescription</key>
<string>使用相机</string>
<key>NSMicrophoneUsageDescription</key>
<string>使用麦克风</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>访问相册</string>
copied to clipboard
IOS限制
当前不支持从iCloud选择视频,当XImagePickerArgsMediaType为Video时且返回的cover为null时,请在
flutter端做相应处理,比如告知用户此视频为iCloud存储,不支持选择,如果要选择此视频,可以到相册打开该视频,等
视频下载完再选择该视频
使用 #
XImagePicker.pickImage(XImagePickerArgs(
type: XImagePickerArgsMediaType.Video,
recordVideoSecond: 10));
copied to clipboard
参数说明 XImagePickerArgs #
final int recordVideoSecond;
/// 最大选择数量
final int maxSelectNum;
/// 选择类型
final XImagePickerArgsMediaType type;
/// 是否显示拍照按钮
final bool isCamera;
XImagePickerArgs(
{this.recordVideoSecond = 60,
this.maxSelectNum = 9,
required this.type,
this.isCamera = true});
copied to clipboard
返回结果XImagePickerResult #
final File file;
final int width;
final int height;
/// 封面,仅当type 为[XImagePickerArgsMediaType.Video]有效
File? cover;
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.