Flutter:如何从 ImagePicker 包的设备中读取图像

Flutter: how to read image from a device for ImagePicker package

我想从我的 android 模拟器 select 一张图片,然后将其上传到云存储。当我调用 File image = await ImagePicker.pickImage(source: ImageSource.gallery); 时,出现如下错误:

MissingPluginException(No implementation found for method requestPermissions on channel flutter.baseflow.com/permissions/methods)

我试图将相机权限放入 AndroidManifest.xml 文件中:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.somethingdwun.dwun">

    <uses-permission android:name="android.permission.CAMERA" />

    <application
        android:name="io.flutter.app.FlutterApplication"
        android:icon="@mipmap/ic_launcher"
        android:label="dwun">
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            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>
        <activity
            android:name="com.yalantis.ucrop.UCropActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
    </application>
</manifest>

谢谢

您是否将其添加到您的依赖项中?

首先,将 image_picker 添加为 pubspec.yaml 文件中的依赖项。 希望对您有所帮助

依赖项:image_picker:^0.6.2+3

我找到了这个MissingPluginException

无需在 AndroidManifest.xml 文件中添加权限。关闭您的应用程序,进入项目目录并在命令行中尝试 运行:

flutter clean

我想它会解决你的问题

有时热重启或热重载不会解决问题。 确保在 pubspec.yaml 文件

中添加 image_picker 作为依赖项

关闭应用程序并执行flutter run命令。