title: How to set image as wallpaper in flutter?
body: <p>I'm confusing in how to set an image as wallpaper in flutter, I have tried to use this code below reference from <a href="https://stackoverflow.com/questions/44181343/how-do-i-share-an-image-on-ios-and-android-using-flutter">here</a>!</p>
  
  <p>my flutter code:
  in this code, I tried to make file from URL </p>
  
  <pre><code>//get URL image and save it and create a file
      _setWallp(String imageUrl) async {
  
  
          try {
            var httpClient = http.Client();
         var list = await httpClient.readBytes(imageUrl);
  
  
            final tempDir = await getTemporaryDirectory();
            final file = await new Io.File('${tempDir.path}/image.jpg').create();
            file.writeAsBytes(list);
  
            final channel = const MethodChannel('setwallpaper');
            channel.invokeMethod('shareFile', 'image.jpg');
          } catch (e) {
            print('Share Error :$e');
          }
        }
  </code></pre>
  
  <p>my java code :
  in this java code, I tried to set bitmap as wallpaper from file path that I created in flutter</p>
  
  <pre><code>//call method channel from flutter
          private static final String SHARE_CHANNEL = "setwallpaper";
  
        @Override
        protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          GeneratedPluginRegistrant.registerWith(this);
  
          new MethodChannel(this.getFlutterView(), SHARE_CHANNEL).setMethodCallHandler(new MethodChannel.MethodCallHandler() {
            public final void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
              if (methodCall.method.equals("shareFile")) {
                shareFile((String) methodCall.arguments);
              }
            }
          });
        }
  
  
            private void shareFile(String path) {
              File imgFile = new  File(this.getApplicationContext().getCacheDir(), path);
  
  
          // set bitmap to wallpaper
              Bitmap bitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
              WallpaperManager wm = WallpaperManager.getInstance(this);
              try{
                wm.setBitmap(bitmap);
              }catch (IOException e){
                Log.e(TAG, "shareFile: cannot set image as wallpaper",e );
              }
            }
          }
  </code></pre>
  
  <p>debug console message:</p>
  
  <pre><code>//message from console
      E/flutter (10376): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
      E/flutter (10376): PlatformException(error, Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference, null)
      E/flutter (10376): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:547:7)
      E/flutter (10376): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:279:18)
      E/flutter (10376): &lt;asynchronous suspension&gt;
      E/flutter (10376): #2      FullScreenState._setWallp (file:///D:/fltr/cat_wallpapers/lib/fullscreen.dart:111:15)
      E/flutter (10376): &lt;asynchronous suspension&gt;
      E/flutter (10376): #3      FullScreenState.build.&lt;anonymous closure&gt; (file:///D:/fltr/cat_wallpapers/lib/fullscreen.dart:71:31)
      E/flutter (10376): #4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:494:14)
      E/flutter (10376): #5      _InkResponseState.build.&lt;anonymous closure&gt; (package:flutter/src/material/ink_well.dart:549:30)
      E/flutter (10376): #6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
      E/flutter (10376): #7      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:161:9)
      E/flutter (10376): #8      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:94:7)
      E/flutter (10376): #9      PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
      E/flutter (10376): #10     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
      E/flutter (10376): #11     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
      E/flutter (10376): #12     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
      E/flutter (10376): #13     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
      E/flutter (10376): #14     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
      E/flutter (10376): #15     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
      E/flutter (10376): #16     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
      E/flutter (10376): #17     _invoke1 (dart:ui/hooks.dart:134:13)
      E/flutter (10376): #18     _dispatchPointerDataPacket (dart:ui/hooks.dart:91:5)
      D/EGL_emulation(10376): eglMakeCurrent: 0xb429e760: ver 2 0
      I/FlutterActivityDelegate(10376): onResume setting current activity to this
      D/EGL_emulation(10376): eglCreateContext: 0xb429e820: maj 2 min 0 rcv 2
      D/EGL_emulation(10376): eglMakeCurrent: 0xb429e820: ver 2 0
      D/EGL_emulation(10376): eglMakeCurrent: 0xb429e760: ver 2 0
      D/EGL_emulation(10376): eglMakeCurrent: 0xb429e820: ver 2 0
      I/flutter (10376): Another exception was thrown: type 'Future&lt;dynamic&gt;' is not a subtype of type 'Future&lt;File&gt;' //didn't understand about this
  </code></pre>
  
  <p>need help.. thank you</p>