I have made a wallpaper app using Flutter. I have used the below package to help user set the wallpaper as HOME, LOCK or BOTH screens. But after setting any image to wallpaper, the whole app gets restarted.

Future<void> _setwallpaper(imagePath, location) async {
var file = await DefaultCacheManager().getSingleFile(imagePath);
WallpaperManagerFlutter().setwallpaperfromFile(file, location);
}
I tried other packages like wallpaper and flutter_wallpaper_manager. However, the same issue exists with these packages as well.
How can I prevent a restart of the flutter app upon setting a wallpaper?