stringlistflutterwallpaper

how to implement string list from _ListItem to assetPath?


i've been working with wallpaper app. i manage to call the path list for wallpaper, i can make this work on image card list but i can't manage to do it work with assetPath for WallpaperManager

Please help, is there any way to do it?

Future<void> setWallpaperFromAsset() async {
setState(() {
  _wallpaperAsset = "Loading";
});
String result;
String assetPath = ('Load List here');

Solution

  • You can add a parameter assetPath to setWallpaperFromAsset

      Future<void> setWallpaperFromAsset(String assetPath) async {
        setState(() {
          _wallpaperAsset = "Loading";
        });
        String result;
        // Platform messages may fail, so we use a try/catch PlatformException.
        try {
          result = await WallpaperManager.setWallpaperFromAsset(
              assetPath, WallpaperManager.HOME_SCREEN);
        } on PlatformException {
          result = 'Failed to get wallpaper.';
        }
      }
    

    And you register the onPressed callback with:

    RaisedButton.icon(
      onPressed: () => setWallpaperFromAsset(item),
      icon: Icon (Icons.wallpaper, size: 20),
      label: Text('homescreen')),
    )