setWallpaperFromFileNative static method
Future<bool>
setWallpaperFromFileNative({
- required String filePath,
- bool goToHome = false,
- ToastDetails? toastDetails,
- ToastDetails? errorToastDetails,
Function takes input image file path, and opens wallpaper apply intent
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> setWallpaperFromFileNative({
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_WALLPAPER_FILE,
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;
}