【问题标题】:Flutter: how to read image from a device for ImagePicker packageFlutter:如何从设备中读取 ImagePicker 包的图像
【发布时间】:2019-12-12 01:29:54
【问题描述】:

我想从我的 android 模拟器中选择一张图片,然后将其上传到云存储。当我打电话给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>

谢谢

【问题讨论】:

  • 从相机或图库中读取图像?如果您尝试从厨房读取,则需要在 android 清单中声明读取存储权限。

标签: flutter imagepicker


【解决方案1】:

我发现了这个MissingPluginException

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

flutter clean

我想它会解决你的问题

【讨论】:

  • 我不必在 AndroidManifest.xml 中添加任何权限。 ImagePicker() 直接在flutter项目目录中flutter clean之后工作。
【解决方案2】:

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

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

依赖:image_picker:^0.6.2+3

【讨论】:

  • 是的,我的依赖项中有它
  • 您能否从您使用此代码的那部分代码中发送一张图片?
【解决方案3】:

有时热重启或热重载不会奏效。 确保在 pubspec.yaml 文件中添加 image_picker 作为依赖项

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-02
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    相关资源
    最近更新 更多