简体   繁体   中英

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');

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')),
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM