Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App ui gets hang while setting wallpaper. #9

Open
athul-ain opened this issue May 25, 2020 · 7 comments
Open

App ui gets hang while setting wallpaper. #9

athul-ain opened this issue May 25, 2020 · 7 comments

Comments

@athul-ain
Copy link

The app gets hang as soon as the function for setting wallpaper is called, and works normally after setting the wallpaper, is there any fix for this.

@houdayec
Copy link

houdayec commented May 28, 2020

Got the same problem here.

Sample of testing code I use:

`Future _setWallpaper(Uint8List wallpaperBytes) async {

final wallpaperPath = await _createFileFromBytes(wallpaperBytes);
print(wallpaperPath);

var success = true;
String result;

int location = WallpaperManager
    .HOME_SCREEN; // or location = WallpaperManager.LOCK_SCREEN;

if (_applyTypeSelected == WallpaperApplyType.both) {
  try {
    result = await WallpaperManager.setWallpaperFromFile(
        wallpaperPath, WallpaperManager.HOME_SCREEN);
  } on PlatformException {
    result = 'Failed to get wallpaper.';
    success = false;
  }

  try {
    result = await WallpaperManager.setWallpaperFromFile(
        wallpaperPath, WallpaperManager.LOCK_SCREEN);
  } on PlatformException {
    result = 'Failed to get wallpaper.';
    success = false;
  }
} else {
  if (_applyTypeSelected == WallpaperApplyType.home) {
    location = WallpaperManager.HOME_SCREEN;
  } else {
    // lock
    location = WallpaperManager.LOCK_SCREEN;
  }
  try {
    result = await WallpaperManager.setWallpaperFromFile(
        wallpaperPath, location);
  } on PlatformException {
    result = 'Failed to get wallpaper.';
    success = false;
  }
}

setState(() {
  _applyingWallpaper = false;
});
return success;

}`

Problem:

UI frames drop, it seems that your methods, though marked as Future, clearly take the main thread to to the applying job.

Any workaround to avoid this problem?

However, this is a very nice library, keep up nice job buddy! :)

@AdityaMulgundkar
Copy link
Owner

Hey @athul-ain, sorry for the late reply, I'm looking into this.

@houdayec I have used platform channels for communicating with the library files at a lower level in Java. (https://flutter.dev/docs/development/platform-integration/platform-channels)

I can use Isolates, if that's what you're suggesting. But I haven't implemented the same because of some issues I've seen with them before (check https://stackoverflow.com/questions/57466952/unable-to-understand-flutter-dart-plugin-isolate-workaround-for-window-sendpla).

Another solution would be to jump to the background thread (and back) as noted in the platform channels wiki. (https://flutter.dev/docs/development/platform-integration/platform-channels?tab=android-channel-kotlin-tab#step-4-add-an-ios-platform-specific-implementation)

Currently, based on the scenario, I think doing a performance analysis & determining the optimum solution will be the best idea.

I can do some performance testing & compare:

  • the current plug-in
  • a function written with Isolates (probably on both ends too)
  • a function that just jumps threads at the platform level while executing

If you meant something else or had any other suggestions, please let me know?

@houdayec
Copy link

houdayec commented Jun 1, 2020

Hey @AdityaMulgundkar ,

You have got right what I meant with this problem. I first thought about using Isolates as you mentioned, it might be more optimised now and would be perfectly Flutter compatible.

I don't know much about background threads with platform channels. If it is platform specific, it might ask much more work though it might be faster. Please let me know.

If you can perform some analysis, it would be really great and helpful. I don't have much time for this deep work, but I will also investigate as soon as I have free time.

@Abhishek201999
Copy link

I had same error, But i fix this error.
This not plugin error, This is nature of flutter, It means if you use async task proper way in Ui main thread this ui hang will not happen( or any frame drops).

I will do these modifications.

  1. Dont keep this task as a part of widget., keep it as seperate function. (it means if any widget depend on this task will hang for little while)

@AdityaMulgundkar Thank you so much for this package. Its working perfectly.

hey could show me example of how you fixed this. I did kept it as a separate function but it still hang for little while

@GAGANsinghmsitece
Copy link

Did anyone find any solution to it?

@aarol
Copy link

aarol commented Apr 30, 2021

I created this issue #25 , can someone take a look at it?

@PraveenGongada
Copy link

I created this issue #25 , can someone take a look at it?

https://pub.dev/packages/wallpaper_manager_flutter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants