簡體   English   中英

Flutter 的 ListView 需要可點擊元素,ListTile 中不顯示前導圖片

[英]Flutter's ListView needs clickable elements, and leading images don't show in ListTile

我正在使用 ListView 在 Dart/Flutter 中編寫一個小應用程序(顯示數據 - 文本和圖像 - 來自互聯網)。 我在這段代碼中有兩個問題要解決。

這是我的代碼(在 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';
    }
}

第一個問題是我需要可點擊元素,ListView 的一個元素:

標題(此處為標題),

字幕(在我的代碼中引導),

領先(帶有imageHref 的圖像),

...需要可點擊。 當用戶點擊它應該打開一個網站(在默認的網絡瀏覽器中),其中 URL 是 href。 我嘗試了來自 Internet 的隨機代碼並嘗試使用 flutter_linkify 和 url_launcher,但它不起作用。 另一方面,當我使用 onTap 時:應用程序會自動(不按任何鍵)打開網頁,這在這里當然是不需要的。

第二個問題是我需要 ListView 中的圖像(前導屬性)。 我想從某個地址以 htpps:// 開頭的網站上使用的圖像,我收到了“握手”錯誤:

(2) Exception caught by image resource service ════════════════════════════════════════════
Handshake error in client (OS Error: 
    CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:354))

我使用了 Image.network(),但它不起作用(我已經讀到此方法會更改用戶代理),因此我決定使用 CachedNetworkImage,但仍然無法查看這些圖像。 圖像的 URL 是正確的,當我從 Chrome 瀏覽器使用它們時,查看圖像沒有問題。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM