Open athul-ain opened 4 years ago
Got the same problem here.
Sample of testing code I use:
`Future
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! :)
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:
If you meant something else or had any other suggestions, please let me know?
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.
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.
- 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
Did anyone find any solution to it?
I created this issue #25 , can someone take a look at it?
I created this issue #25 , can someone take a look at it?
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.