setWallpaper static method
Future<bool>
setWallpaper({
- required String url,
- int wallpaperLocation = BOTH_SCREENS,
- bool goToHome = false,
- ToastDetails? toastDetails,
- ToastDetails? errorToastDetails,
Function takes input url's image & location choice, and applies wallpaper depending on location choice
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> setWallpaper({
required String url,
int wallpaperLocation = BOTH_SCREENS,
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': url,
'goToHome': goToHome,
};
String location = _SET_BOTH_WALLPAPER;
switch (wallpaperLocation) {
case HOME_SCREEN:
location = _SET_HOME_WALLPAPER;
break;
case LOCK_SCREEN:
location = _SET_LOCK_WALLPAPER;
break;
case BOTH_SCREENS:
location = _SET_BOTH_WALLPAPER;
break;
default:
location = _SET_BOTH_WALLPAPER;
break;
}
result = await _channel.invokeMethod(
location,
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;
}