Giter VIP home page Giter VIP logo

wallpaper_manager's Introduction

wallpaper_manager

Wallpaper Manager

A Flutter plugin for changing the Home Screen, Lock Screen (or both) Wallpaper(s) on Android devices.

Pub

Usage

Installation

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  wallpaper_manager: "^1.0.10"

In your library add the following import:

import 'package:wallpaper_manager/wallpaper_manager.dart';

Example

Basic Usage

Since this is not a Widget, you have to create WallpaperManager constructors from inside an async function, which is a Future that returns a String output specifying success/failure.

String path = "/path/to/file/on/disk";
int location = WallpaperManager.HOME_SCREEN; // or location = WallpaperManager.LOCK_SCREEN;
final String result = await WallpaperManager.setWallpaperFromFile(path, location);

Basic Usage with error handling

You might want to wrap it in a try/catch since platform messages (plug-ins like these) may fail

String path = "/path/to/file/on/disk";
int location = WallpaperManager.HOME_SCREEN; // or location = WallpaperManager.LOCK_SCREEN;
String result;
try {
  result = await WallpaperManager.setWallpaperFromFile(path, location);
} on PlatformException {
  result = 'Failed to get wallpaper.';
}

Loading from a URL (with CacheManager, the image is saved to app files as well)

If you're loading a Wallpaper from a URL, you should save it to the disk first, then use the path of the saved image file. Add flutter_cache_manager or any other dependency you'd like:

dependencies:
  ...
  flutter_cache_manager: "^1.1.3"

And in dart code

String url = "";
int location = WallpaperManager.HOME_SCREEN; // or location = WallpaperManager.LOCK_SCREEN;
String result;
var file = await DefaultCacheManager().getSingleFile(url);
final String result = await WallpaperManager.setWallpaperFromFile(file.path, location);

Loading from a Flutter asset

If you're loading a Wallpaper from an asset, you need to make sure it is indexed in the pubspec.yaml file first

dependencies:
  ...
  flutter:
    ...
    assets:
    - assets/tmp1.jpeg

And in dart code

String assetPath = "assets/tmp1.jpg";
int location = WallpaperManager.HOME_SCREEN; // or location = WallpaperManager.LOCK_SCREEN;
String result;
final String result = await WallpaperManager.setWallpaperFromAsset(assetPath, location);

Getting started

With Wallpaper Manager

See the example directory for a complete sample app using Wallpaper Manager.

With Flutter

For help getting started with Flutter, view the online documentation.

Notes

  • iOS does not support changing Wallpapers from third-party apps (Source)
  • Xiaomi/MIUI does not support changing Lock Screen Wallpapers directly from the Android API (Source). You might want to look at creating a Lock Screen Launcher app instead.

Known Issues

Todos

  • Write tests
  • Add rect values for optionally cropping the image
  • Add variable for re-using Wallpaper from phone's settings
  • Write more tests

Changelog

Please see the Changelog page to know what's recently changed.

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a feature, please send a pull request.

wallpaper_manager's People

Contributors

adityamulgundkar avatar codenameakshay avatar apoorvaaditya avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.