简体   繁体   English

我想在 flutter 中创建一个带有 firebase 的列表视图,它将显示标题副标题和图像,并且当用户单击将打开 web 视图的列表视图时

[英]i want to create a listview with firebase in flutter that will show title subtitle and image and when user click on listview that will open a webview

I sm creating a flutter app where i want to create a listview with firebase in flutter that will show title subtitle and image and when user click on listview that will open a webview but I want the web view URL should come from the firebase title subtitle and the image part already working I stuck in the URL part please help how to do this我创建了一个 flutter 应用程序,我想在 flutter 中创建一个带有 firebase 的列表视图,它将显示标题副标题和图像,当用户单击将打开 web 视图的列表视图时,但我希望 web 视图 URL 应该来自 firebase 标题副标题和图像部分已经工作我卡在 URL 部分请帮助如何做到这一点

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:watched_movie_list/Widget/webviewx.dart';

class ListviewPage extends StatefulWidget {
  final firBaseLists;
  final String webviewTitle;
  final String weburl;

  ListviewPage(
      {this.firBaseLists, required this.webviewTitle, required this.weburl});

  @override
  _ListviewPageState createState() => _ListviewPageState();
}

class _ListviewPageState extends State<ListviewPage> {
  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
      stream: FirebaseFirestore.instance.collection('listview').snapshots(),
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
      if (!snapshot.hasData) {
         return Center(
            child: CupertinoActivityIndicator(
              radius: 20,
            ),
          );
        }
        return Scaffold(
          appBar: AppBar(
            title: Text(
              ' नवीनतम सूचनाएं',
              style: TextStyle(color: Colors.black),
            ),
            leading: BackButton(color: Colors.black),
            backgroundColor: Colors.white,
          ),
          body: Container(
            height: 800,
            color: Color(0xfff5f5f5),
            child: ListView(
              children: snapshot.data!.docs.map((DocumentSnapshot document) {
                Map<String, dynamic> data =
                    document.data()! as Map<String, dynamic>;
                return InkWell(
                  onTap: () {
                    Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (context) => InAppWebViewx(
                                  title: widget
                                      .firBaseLists["${data['titletext']}"],
                                  url: widget.firBaseLists("${data['url']}"),
                                )));
                  },
                  child: Container(
                    height: 150,
                    decoration: BoxDecoration(
                        color: Colors.lightGreen,
                        borderRadius: BorderRadius.circular(18)),
                    margin:
                        EdgeInsets.only(top: 8, right: 12, left: 12, bottom: 2),
                    child: Row(
                      children: [
                        Container(
                          padding: const EdgeInsets.only(top: 15, left: 20),
                          height: 150,
                          width: 330,
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Image.network(
                                "${data['img']}",
                                height: 40,
                                width: 40,
                              ),
                              Padding(
                                padding: const EdgeInsets.only(top: 8.0),
                                child: Text(
                                  "${data['titletext']}",
                                  style: TextStyle(
                                    fontSize: 15,
                                    fontWeight: FontWeight.bold,
                                    color: Colors.white,
                                  ),
                                ),
                              ),
                              Padding(
                                padding: const EdgeInsets.only(top: 8.0),
                                child: Text(
                                  "${data['subtitle']}",
                                  maxLines: 2,
                                  style: TextStyle(
                                    fontSize: 12,
                                    fontWeight: FontWeight.bold,
                                    color: Colors.white,
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                );
              }).toList(),
            ),
          ),
        );
      },
    );
  }
}```

You should use Listview.builder instead of Listview.您应该使用Listview.builder而不是 Listview。 Inside the Listview.builder you could capture the data with index of the itemBuilder and pass it to the WebView.在 Listview.builder 中,您可以使用 itemBuilder 的索引捕获数据并将其传递给 WebView。 Here's the link to get started on Listview.builder https://www.geeksforgeeks.org/listview-builder-in-flutter/这是开始使用 Listview.builder 的链接https://www.geeksforgeeks.org/listview-builder-in-flutter/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 ListView 中显示来自 Firebase 的 TextView 和图像 - Show in a ListView a TextView and Image from Firebase 在来自数据库 firebase 的列表视图 url 图像中显示 - Show in listview url image from database firebase 在ListView中显示Firebase中的TextView和图像 - Show in a ListView a TextView and an Image from Firebase 当我手动更改 firebase 数据库中的值时,我在 listview 中创建了更多项目,而不是在 listview 中更新值 - when I manually change value in firebase database I create more items in listview instead of updating value in listview 在 ListView 中显示 Firebase 数据 - Show Firebase data in ListView 我试图通过从 firebase 实时数据库中获取链接来在自定义列表视图中显示图像,但未显示图像 - I am trying to show an image in a custom listview by taking a link from a firebase realtime database, but the image is not shown 使用身份验证用户从Firebase检索数据不会显示在ListView上 - retrieve data from firebase with authentication user do not show on ListView Flutter 与 Firebase-Firestore(列表视图) - Flutter with Firebase-Firestore (listview) 我想通过在列表视图项上使用 longclick 从 firebase 中删除数据 - i want to delete data from firebase by using longclick on the listview item 我想根据用户是否经过身份验证打开适当的 window 。 Firebase Flutter - I want to open the appropriate window depending on whether the user is authenticated or not. Firebase Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM