颤振';s的ListView需要可单击的元素,并且前导图像不';不能在列表中显示

颤振';s的ListView需要可单击的元素,并且前导图像不';不能在列表中显示,listview,flutter,dart,Listview,Flutter,Dart,我正在用Dart/Flatter和ListView编写一个小应用程序(显示来自Internet的数据-文本和图像)。在这段代码中,我有两个问题需要解决 以下是我的代码(在ListView中显示数据的部分): 第一个问题是我需要clickable元素,ListView的一个元素: ListView _testsListView(data) { return ListView.builder( itemCount: data.length, itemBui

我正在用Dart/Flatter和ListView编写一个小应用程序(显示来自Internet的数据-文本和图像)。在这段代码中,我有两个问题需要解决

以下是我的代码(在ListView中显示数据的部分):

第一个问题是我需要clickable元素,ListView的一个元素:

  ListView _testsListView(data) {
    return ListView.builder(
        itemCount: data.length,
        itemBuilder: (context, index) {
          return _tile(data[index].title, data[index].lead, data[index].href, data[index].imageHref);
        });
  }

  ListTile _tile(String title, String lead, String href, String imageHref) => ListTile(

    subtitle: Text(lead,
        style: TextStyle(
          fontWeight: FontWeight.w500,
          fontSize: 12,
          color: Colors.green,
        )),
    title: Text(title,
      style: TextStyle(color: Colors.blue),
    ),
    leading: CachedNetworkImage(
      imageUrl: imageHref,
      fit: BoxFit.cover,
      alignment: Alignment.centerLeft,
      placeholder: (context, url) => CircularProgressIndicator(),
      errorWidget: (context, url, error) => Icon(Icons.error),
    ),
  );
}

void launchWeb(String URL) async
{
    if (await canLaunch(URL)) {
      await launch(URL);
    } else {
      throw 'Could not launch $URL';
    }
}
标题(title此处)

子主题(我的代码中的lead

领先(图像带有imageHref

…需要可点击。当用户单击时,应打开一个URL为href的网站(在默认web浏览器中)。我从互联网上尝试了随机代码,并尝试了Flitter_linkify和url_launcher,但都不起作用。 另一方面,当我使用onTap:application时,它会自动(不按任何键)打开网页,这在这里当然是不需要的

第二个问题是我需要ListView中的图像(前导属性)。我想从某个地址以htpps://开头的网站上使用的图像,但出现了“握手”错误:


我使用了Image.network(),但它不起作用(我已了解到此方法会更改用户代理),因此我决定使用CachedNetworkImage,但在查看这些图像时仍然存在问题。图像的URL是正确的,当我从Chrome浏览器使用它们时,查看图像没有问题。

另一方面,当我使用onTap时:应用程序自动(不按任何键)打开网页,这当然不是这里想要的。
你能展示一下你是如何使用
onTap
的吗?我记得我是这样使用的:onTap:launchWeb(href);这样使用:
onTap:()=>launchWeb(href)
。它打开WebView而不单击的原因是您在分配.OK,Lambda表达式时调用函数。我现在明白我的错误了。谢谢。我只能在整个ListTile中使用onTap,但是如何在一个元素中使用它:标题、副标题或前导?对我不起作用。获取错误:“未定义子参数”您可以找到获取错误的行!你试过什么??邮政编码!我已将您的代码粘贴到我的ListTitle定义中,第一次出现“child”单词时会显示错误。请更改url并尝试将缓存的网络映像的小部件更改为其他网络映像!我会听从你的建议。
   return ListTile(
            onTap:(){
            //list tile tap
              }
             ),
             title: InkWell(
                 child: Text('Title'),
                 onTap:(){
               //title tap
                 }
             ),
             subtitle:InkWell(
                 child: Text('Sub Title'),onTap:(){
               //sub title tap
                 }
             ),),
             leading:InkWell(
                 onTap:(){
                 //title tap
                  }
                 ),
                 child: CachedNetworkImage(
                      imageUrl: imageHref,
                      fit: BoxFit.cover,
                      alignment: Alignment.centerLeft,
                      placeholder: (context, url) => CircularProgressIndicator(),
                      errorWidget: (context, url, error) => Icon(Icons.error),
                    ),
                  )
                )
   return ListTile(
            onTap:(){
            //list tile tap
              }
             ),
             title: InkWell(
                 child: Text('Title'),
                 onTap:(){
               //title tap
                 }
             ),
             subtitle:InkWell(
                 child: Text('Sub Title'),onTap:(){
               //sub title tap
                 }
             ),),
             leading:InkWell(
                 onTap:(){
                 //title tap
                  }
                 ),
                 child: CachedNetworkImage(
                      imageUrl: imageHref,
                      fit: BoxFit.cover,
                      alignment: Alignment.centerLeft,
                      placeholder: (context, url) => CircularProgressIndicator(),
                      errorWidget: (context, url, error) => Icon(Icons.error),
                    ),
                  )
                )