x_image_picker 0.0.1+1
x_image_picker: ^0.0.1+1 copied to clipboard

A new Flutter project.

x_image_picker #

flutter 图片和视频选择器

Android设置 #

  1. 修改最低SDK版本为19, 文件路径android/app/build.gradle
defaultConfig {
        applicationId "com.huanshao.x_image_picker_example"
        minSdkVersion 19 // here
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
  1. 添加依赖androidx.camera:camera-camera2
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "androidx.camera:camera-camera2:1.1.0-alpha06" // here
}
  1. 修改android/build.gradlekotlin_version的版本为1.4.32
ext.kotlin_version = '1.4.32'
  1. 添加application类, 并在AndroidManifest.xmlapplication标签中声明
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();
    }
}
<application
        android:label="x_image_picker_example"
        android:icon="@mipmap/ic_launcher"
       android:name=".MyApplication"
       >
.......
</application>
  1. 添加权限
<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" />

IOS设置 #

  1. 添加权限描述
<key>NSCameraUsageDescription</key>
<string>使用相机</string>
<key>NSMicrophoneUsageDescription</key>
<string>使用麦克风</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>访问相册</string>
  1. IOS限制

    当前不支持从iCloud选择视频,当XImagePickerArgsMediaTypeVideo时且返回的cover为null时,请在 flutter端做相应处理,比如告知用户此视频为iCloud存储,不支持选择,如果要选择此视频,可以到相册打开该视频,等 视频下载完再选择该视频

使用 #

XImagePicker.pickImage(XImagePickerArgs(
                    type: XImagePickerArgsMediaType.Video,
                    recordVideoSecond: 10));

参数说明 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});

返回结果XImagePickerResult #

final File file;
  final int width;
  final int height;

  /// 封面,仅当type 为[XImagePickerArgsMediaType.Video]有效
  File? cover;