如何修复在flutter应用程序中下载图像的image_picker_saver错误

时间:2019-05-07 15:54:56

标签: dart flutter download

使用image_picker_saver软件包从我的flutter应用程序下载图像时出现错误,当我从pubsec.yaml和saveImage小部件中删除image_picker_saver时,该应用程序运行良好,但是当我将image_picker_saver软件包添加到代码中时却出现错误。 / p>

运行控制台输出-

 C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:15: error: package android.support.annotation does not exist
    import android.support.annotation.VisibleForTesting;
                                     ^
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:16: error: cannot find symbol
    import android.support.v4.app.ActivityCompat;
                                 ^
      symbol:   class ActivityCompat
      location: package android.support.v4.app
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:17: error: package android.support.v4.content does not exist
    import android.support.v4.content.FileProvider;
                                     ^
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerFileProvider.java:3: error: package android.support.v4.content does not exist
    import android.support.v4.content.FileProvider;
                                     ^
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerFileProvider.java:10: error: cannot find symbol
    public class ImagePickerFileProvider extends FileProvider {
                                                 ^
      symbol: class FileProvider
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerSaverPlugin.java:8: error: package android.support.annotation does not exist
    import android.support.annotation.VisibleForTesting;
                                     ^
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:70: error: cannot find symbol
        @VisibleForTesting
         ^
      symbol:   class VisibleForTesting
      location: class ImagePickerDelegate
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:72: error: cannot find symbol
        @VisibleForTesting
         ^
      symbol:   class VisibleForTesting
      location: class ImagePickerDelegate
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:74: error: cannot find symbol
        @VisibleForTesting
         ^
      symbol:   class VisibleForTesting
      location: class ImagePickerDelegate
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:76: error: cannot find symbol
        @VisibleForTesting
         ^
      symbol:   class VisibleForTesting
      location: class ImagePickerDelegate
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:78: error: cannot find symbol
        @VisibleForTesting
         ^
      symbol:   class VisibleForTesting
      location: class ImagePickerDelegate
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:80: error: cannot find symbol
        @VisibleForTesting
         ^
      symbol:   class VisibleForTesting
      location: class ImagePickerDelegate
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:82: error: cannot find symbol
        @VisibleForTesting
         ^
      symbol:   class VisibleForTesting
      location: class ImagePickerDelegate
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:84: error: cannot find symbol
        @VisibleForTesting
         ^
      symbol:   class VisibleForTesting
      location: class ImagePickerDelegate
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:87: error: cannot find symbol
        @VisibleForTesting
         ^
      symbol:   class VisibleForTesting
      location: class ImagePickerDelegate
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:176: error: cannot find symbol
        @VisibleForTesting
         ^
      symbol:   class VisibleForTesting
      location: class ImagePickerDelegate
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerSaverPlugin.java:44: error: cannot find symbol
        @VisibleForTesting
         ^
      symbol:   class VisibleForTesting
      location: class ImagePickerSaverPlugin
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:133: error: cannot find symbol
                            return ActivityCompat.checkSelfPermission(activity, permissionName)
                                   ^
      symbol: variable ActivityCompat
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:139: error: cannot find symbol
                            ActivityCompat.requestPermissions(activity, new String[]{permissionName}, requestCode);
                            ^
      symbol: variable ActivityCompat
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker_saver-0.1.0\android\src\main\java\io\flutter\plugins\imagepickersaver\ImagePickerDelegate.java:151: error: cannot find symbol
                            return FileProvider.getUriForFile(activity, fileProviderName, file);
                                   ^
      symbol: variable FileProvider
    20 errors

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':image_picker_saver:compileDebugJavaWithJavac'.
    > Compilation failed; see the compiler error output for details.

    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

    * Get more help at https://help.gradle.org

    BUILD FAILED in 2m 27s
    *******************************************************************************************
    The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.

    *******************************************************************************************
    Finished with error: Gradle task assembleDebug failed with exit code 1

部分代码-

class FullScreenImagePage extends StatelessWidget {
  String imgPath;

  FullScreenImagePage(this.imgPath);
   @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: new SizedBox.expand(
        child: new Container(
          decoration: new BoxDecoration(gradient: backgroundGradient),
          child: new Stack(
            children: <Widget>[
              new Align(
                alignment: Alignment.center,
                child: new Hero(
                  tag: imgPath,
                  child: new Image.network(imgPath),
                ),
              ),
              new Align(
                alignment: Alignment.topCenter,
                child: new Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[


 Align(alignment: Alignment.bottomCenter,
                child: IconButton(
                  icon: Icon(Icons.file_download,
                      color: Colors.black),
                  onPressed: () =>
                   _saveImage(imgPath)
                ),
              ),


  _saveImage(imageNames) async {
    await PermissionHandler()
        .checkPermissionStatus(PermissionGroup.storage)
        .then((status) async {
      if (status == PermissionStatus.denied ||
          status == PermissionStatus.disabled ||
          status == PermissionStatus.unknown) {
        await PermissionHandler().requestPermissions(
            [PermissionGroup.storage]).then((status1) async {
          if (status1.containsValue(PermissionStatus.granted)) {
            await get(imageNames).then((res) async {
              await ImagePickerSaver.saveFile(fileData: res.bodyBytes)
                  .then((str) {
                File.fromUri(Uri.file(str));
                Fluttertoast.showToast(
                    msg: "Saved to gallery!",
                    toastLength: Toast.LENGTH_LONG,
                    gravity: ToastGravity.BOTTOM,
                    timeInSecForIos: 1,
                    backgroundColor: Colors.green,
                    textColor: Colors.white,
                    fontSize: 15.0);
              });
            });
          }
        });
      } else if (status == PermissionStatus.granted) {
        await get(imageNames).then((res) async {
          await ImagePickerSaver.saveFile(fileData: res.bodyBytes).then((str) {
            File.fromUri(Uri.file(str));
            Fluttertoast.showToast(
                msg: "Saved to gallery!",
                toastLength: Toast.LENGTH_LONG,
                gravity: ToastGravity.CENTER,
                timeInSecForIos: 1,
                backgroundColor: Colors.green,
                textColor: Colors.white,
                fontSize: 15.0);
          });
        });
      }
    });
  }
 in pubsec.yaml-
  image_picker_saver: ^0.1.0

0 个答案:

没有答案