setLiveWallpaper static method

Future<bool> setLiveWallpaper(
  1. {required String filePath,
  2. bool goToHome = false,
  3. ToastDetails? toastDetails,
  4. ToastDetails? errorToastDetails}
)

Function takes input live file path, and shows live wallpaper activity You can also set the bool goToHome to instruct the app to take the user to the home screen to show the set wallpaper. If wallpaper set fails, user won't be taken to home screen.

Implementation

static Future<bool> setLiveWallpaper({
  required String filePath,
  bool goToHome = false,
  ToastDetails? toastDetails,
  ToastDetails? errorToastDetails,
}) async {
  /// Variable to store operation result
  bool result = false;

  // The paramters for the method call
  final options = {
    'url': filePath,
    'goToHome': goToHome,
  };

  result = await _channel.invokeMethod(
    _SET_VIDEO_WALLPAPER,
    options,
  );

  if (toastDetails != null && result) {
    Fluttertoast.showToast(
      msg: toastDetails.message,
      backgroundColor: toastDetails.backgroundColor,
      fontSize: toastDetails.fontSize,
      gravity: toastDetails.gravity,
      textColor: toastDetails.textColor,
      toastLength: toastDetails.toastLength,
    );
  }

  if (errorToastDetails != null && !result) {
    Fluttertoast.showToast(
      msg: errorToastDetails.message,
      backgroundColor: errorToastDetails.backgroundColor,
      fontSize: errorToastDetails.fontSize,
      gravity: errorToastDetails.gravity,
      textColor: errorToastDetails.textColor,
      toastLength: errorToastDetails.toastLength,
    );
  }

  /// Function returns the bool result, use for debugging or showing toast message
  return result;
}