【问题标题】:The argument type 'List<String>' can't be assigned to the parameter type 'String'. How can I solve this problem?不能将参数类型 \'List<String>\' 分配给参数类型 \'String\'。我怎么解决这个问题?
【发布时间】:2022-11-17 20:06:53
【问题描述】:

我已经学习 flutter 两个月了。我正在尝试开发壁纸应用程序。我创建了一个模型和一个函数。但是现在我只能下载 1 张壁纸。我怎样才能把这个列成一个清单?我在列清单时收到此错误。

这是网址。

  String url =
      'https://images.hdqwalls.com/download/the-witcher-season-2-2022-5k-u1-1080x1920.jpg';

我要使用的列表

  List<String> url = [
    'https://images.hdqwalls.com/download/the-witcher-season-2-2022-5k-u1-1080x1920.jpg',
    'https://images.hdqwalls.com/download/the-witcher-season-2-2022-5k-u1-1080x1920.jpg',
  ];

和功能

  void saveimage() async {
    await GallerySaver.saveImage(url, albumName: album_name);
  }

单击此按钮提供下载

 ElevatedButton DownloadButton(BuildContext context) {
    return ElevatedButton(
      style: ElevatedButton.styleFrom(
        minimumSize: Size(40, 40),
        shape: CircleBorder(),
        backgroundColor: Colors.grey.shade600.withOpacity(0.1),
      ),
      child: Icon(Icons.download, color: Colors.white.withOpacity(0.7)),
      onPressed: () {
        saveimage();
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            duration: Duration(seconds: 2),
            content: Text('Wallpaper downloaded!'),
            action: SnackBarAction(
              label: '',
              onPressed: () {},
            ),
          ),
        );
      },
    );
  }

Problem image

我使用的包是

  • 画廊保护程序:^2.3.2
  • async_wallpaper: ^2.0.1

我想在 gridview 中使用它

GridView.builder(
        itemCount: url.length,
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 2,
          childAspectRatio: 9 / 16,
        ),
        itemBuilder: (BuildContext context, int index) {
          return Card(
            child: Padding(
              padding: EdgeInsets.all(1.0),
              child: FullScreenWidget(
                child: Stack(fit: StackFit.expand, children: [
                  Image.network(url, fit: BoxFit.cover),

【问题讨论】:

    标签: flutter flutter-dependencies flutter-test


    【解决方案1】:
    void saveimage() async {
        await GallerySaver.saveImage(url[0], albumName: album_name);
      }
    

    上面的代码将解决您的错误

    【讨论】:

      猜你喜欢
      • 2021-10-06
      • 2020-08-26
      • 2022-08-13
      • 1970-01-01
      • 2022-12-12
      • 2021-10-02
      • 2021-09-13
      • 2020-04-15
      • 2021-09-06
      相关资源
      最近更新 更多