Nammar Mahsud
Nammar Mahsud

Reputation: 131

Why Flutter app gets restarted upon setting a wallpaper or Live Wallpaper?

I am using async_wallpaper package and this is the function

 Future<void> setLiveWallpaper(String liveUrl) async {
    setState(() {
      _liveWallpaper = 'Loading';
    });
    String result;
    var file = await DefaultCacheManager().getSingleFile(liveUrl);
    try {
      result = await AsyncWallpaper.setLiveWallpaper(
        filePath: file.path,
        goToHome: true,//tried false also
        toastDetails: ToastDetails.success(),
        errorToastDetails: ToastDetails.error(),
      )
          ? 'Live Wallpaper set'
          : 'Failed to set live wallpaper.';
    } on PlatformException catch (e) {
      print('PlatformException>>>>>>>>>>>>>.: $e');
      result = 'Failed to set live wallpaper.';
    }
    if (!mounted) return;

    setState(() {
      _liveWallpaper = result;
    });
  }

this is where i dispaly the live wallpapers thumbnails

After Click one of the wallpaper it shows the wallpaper preview

Now look here the problem is it opens a new activity (new tab for preview). After successfully applying the wallpaper when it comes back to the app it starts from splash screen

Upvotes: 0

Views: 232

Answers (1)

Zain
Zain

Reputation: 1

you can set SystemNavigator.pop in this function to close the app after applying the wallpaper. this will be a good approach for the user because in almost every app this method is used where when the user applies the wallpaper then the app closed and the wallpaper shows to the user.

Upvotes: 0

Related Questions