Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Flatter从firebase中的子集合读取或检索数据列表_Firebase_Flutter_Dart_Google Cloud Firestore - Fatal编程技术网

使用Flatter从firebase中的子集合读取或检索数据列表

使用Flatter从firebase中的子集合读取或检索数据列表,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,我使用firebase保存我的数据,并使用Flatter(dart)访问这些数据 现在。我有一个收款名称(客户付款详细信息),我把这样的随机唯一ID(tZ9d9cYeUvXKm1easHtr)放在这个ID中,我有一个子收款(付款信息)。在这个子集合中有一个唯一的ID。在这个ID中有许多值 我想以列表的形式读取此数据 我写这段代码是为了访问这些数据 下面的代码是我的型号名称(客户\付款\详细信息) 这是我的API: import 'package:cloud_firestore/cloud_fir

我使用firebase保存我的数据,并使用Flatter(dart)访问这些数据 现在。我有一个收款名称(客户付款详细信息),我把这样的随机唯一ID(tZ9d9cYeUvXKm1easHtr)放在这个ID中,我有一个子收款(付款信息)。在这个子集合中有一个唯一的ID。在这个ID中有许多值

我想以列表的形式读取此数据

我写这段代码是为了访问这些数据

下面的代码是我的型号名称(客户\付款\详细信息)

这是我的API:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'dart:async';

class payment_api {
 final Firestore _db = Firestore.instance;
 final String path;
 CollectionReference ref;

 payment_api(this.path) {
   ref = _db.collection(path);
  }

  Future<QuerySnapshot> getDataCollection() {
   return ref.getDocuments();
  }

  Stream<QuerySnapshot> streamDataCollection() {
    return ref.snapshots();
  }

  Future<DocumentSnapshot> getDocumentById(String id) {
   return ref.document(id).get();
  }

  Future<void> removeDocument(String id) {
    return ref.document(id).delete();
  }

   Future<DocumentReference> addDocument(Map data, String customer_id) {
    return ref.document(customer_id).collection("Payment_info").add(data);
   }

   Future<void> updateDocument(Map data, String id) {
    return ref.document(id).updateData(data);
  }
 }
import'包:cloud_firestore/cloud_firestore.dart';
导入“dart:async”;
类别付款(api){
final Firestore _db=Firestore.instance;
最终字符串路径;
收集参考文献;
支付api(this.path){
ref=_db.collection(路径);
}
未来的getDataCollection(){
返回参考getDocuments();
}
streamDataCollection()流{
返回参考快照();
}
未来的getDocumentById(字符串id){
返回ref.document(id).get();
}
未来removeDocument(字符串id){
返回参考文档(id).delete();
}
Future addDocument(地图数据、字符串customer\u id){
返回参考文件(客户id)。收款(“付款信息”)。添加(数据);
}
未来更新文档(地图数据、字符串id){
返回参考文件(id).updateData(数据);
}
}
这是我的屏幕:

import 'package:cloud_firestore/cloud_firestore.dart';
 import 'package:flutter/material.dart';
 import 'package:login_example/CustomerCore/models/cstomer_payment_detailsModel.dart';
 import 'package:login_example/CustomerCore/models/productModel.dart';
 import 'package:login_example/CustomerCore/viewmodels/CRUDModel.dart';
 import 'package:login_example/CustomerCore/viewmodels/customer_paymentCRUD.dart';
 import 'package:login_example/uiCustomer/widgets/payment_details_card.dart';
 import 'package:login_example/uiCustomer/widgets/productCard.dart';
 import 'package:provider/provider.dart';

 class payment_details_view extends StatefulWidget {
   @override
   _payment_details_viewState createState() => _payment_details_viewState();
 }

 class _payment_details_viewState extends State<payment_details_view> {
   List<Customer_payment_details> customers_information;

  @override
   Widget build(BuildContext context) {
    final productProvider = Provider.of<customer_paymentCRUD>(context);

   return Scaffold(
  appBar: AppBar(
    backgroundColor: Colors.deepPurple,
    title: Center(child: Text('ايوب محمد ابراهيم')),
  ),
  body: Container(
    child: StreamBuilder(
        stream:   productProvider.fetchcustomer_paymentsAsStream(),
        builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
          if (snapshot.hasData) {
            customers_information = snapshot.data.documents
                .map((doc) => Customer_payment_details.fromMap_details(doc.data, 
           doc.documentID)).toList();
            return ListView.builder(
              itemCount: customers_information.length,
              itemBuilder: (buildContext, index) => payment_details_card(
                  customer_details: customers_information[index]),
            );
import'包:cloud_firestore/cloud_firestore.dart';
进口“包装:颤振/材料.省道”;
导入“包:登录\示例/CustomerCore/models/cstomer\付款\详细信息model.dart”;
导入“包:登录\示例/CustomerCore/models/productModel.dart”;
导入“包:登录\示例/CustomerCore/viewmodels/CRUDModel.dart”;
导入“包:登录\示例/CustomerCore/viewmodels/customer\付款方式crud.dart”;
导入“包:登录\示例/uiCustomer/widgets/payment \详细信息\卡.dart”;
导入“包:login_示例/uiCustomer/widgets/productCard.dart”;
导入“包:provider/provider.dart”;
类付款\u详细信息\u视图扩展StatefulWidget{
@凌驾
_付款\详细信息\视图状态createState()=>\付款\详细信息\视图状态();
}
类\付款\详细信息\视图状态扩展状态{
列出客户信息;
@凌驾
小部件构建(构建上下文){
final productProvider=Provider.of(上下文);
返回脚手架(
appBar:appBar(
背景颜色:颜色。深紫色,
标题:中心(子项:文本),
),
主体:容器(
孩子:StreamBuilder(
流:productProvider.fetchcustomer\u paymentsAsStream(),
生成器:(上下文,异步快照){
if(snapshot.hasData){
客户信息=snapshot.data.documents
.map((doc)=>客户付款详情。从map\u详情(doc.data,
doc.documentID)).toList();
返回ListView.builder(
itemCount:customers\u information.length,
itemBuilder:(buildContext,index)=>付款详细信息\u卡(
客户详细信息:客户信息[索引],
);
这是我的名片:

类付款\u详细信息\u卡{ 最终客户付款详情客户详情

MoneyFormatterOutput fmf;
String convert_value (String value){
fmf = FlutterMoneyFormatter(
    amount: double.parse(value),
    settings: MoneyFormatterSettings(
        symbol: 'د.ع',
        thousandSeparator: ',',
        decimalSeparator: '.',
        symbolAndNumberSeparator: ' ',
        fractionDigits: 0,
        compactFormatType: CompactFormatType.short
    )
).output;
return fmf.symbolOnLeft;
 }
 payment_details_card({@required this.customer_details});


  @override
  Widget build(BuildContext context) {
return GestureDetector(
  onTap: (){
  //  Navigator.push(context, MaterialPageRoute(builder: (_) => CustomerProfilePage(customer_info: 
 customer_details)));
    print(customer_details.id);
  },
  child: Padding(
    padding: EdgeInsets.all(8),
    child: Card(
      elevation: 10,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(15.0),
      ),
      child: Container(
        height: MediaQuery
            .of(context)
            .size
            .height * 0.30,
        width: MediaQuery
            .of(context)
            .size
            .width * 0.9,
        child: Column(
          children: <Widget>[
            Hero(
                tag: customer_details.customer_id,

                child :   Material(
                  color: Colors.white70,
                  child: Column(

                    crossAxisAlignment: CrossAxisAlignment.center,

                    children: <Widget>[
                      Padding(
                        padding: EdgeInsets.only(right: 10.0 , top: 15.0),
                        child:   Text(

                          //اسم الزبون
                          customer_details.customer_id,

                          textDirection: TextDirection.rtl,

                          style: TextStyle(
                            fontFamily: 'JannaLT-Regular',
                            fontWeight: FontWeight.w900,
                            fontSize: 22,
                            color:  Colors.black,


                          ),
                        ),
                      ),
moneyformatter输出fmf;
字符串转换_值(字符串值){
fmf=格式化程序(
金额:double.parse(值),
设置:MoneyFormatterSettings(
符号:“د.ع”,
千位分隔符:',',
小数分隔符:''.'',
符号与编号分隔符:“”,
分位数:0,
compactFormatType:compactFormatType.short
)
).产出;
返回fmf.symbolOnLeft;
}
付款详情卡({@required this.customer\u details});
@凌驾
小部件构建(构建上下文){
返回手势检测器(
onTap:(){
//Navigator.push(上下文,MaterialPage)(生成器:()=>CustomerProfilePage(客户信息:
顾客(详情),;
打印(客户详细信息.id);
},
孩子:填充(
填充:边缘设置。全部(8),
孩子:卡片(
标高:10,
形状:圆形矩形边框(
边界半径:边界半径。圆形(15.0),
),
子:容器(
高度:MediaQuery
.of(上下文)
.尺寸
.高度*0.30,
宽度:MediaQuery
.of(上下文)
.尺寸
.宽度*0.9,
子:列(
儿童:[
英雄(
标签:customer\u details.customer\u id,
儿童:材料(
颜色:颜色。白色70,
子:列(
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
填充物(
填充:仅限边缘设置(右侧:10.0,顶部:15.0),
子:文本(
//اسم الزبون
customer\u details.customer\u id,
textDirection:textDirection.rtl,
样式:TextStyle(
fontFamily:“Jannart常规”,
fontWeight:fontWeight.w900,
尺寸:22,
颜色:颜色,黑色,
),
),
),
等等

下图显示了数据库:

这张图片是用来收集的

我想将此数据作为listview加载到卡中。有人能帮我吗?

检查此代码

       stream:   productProvider.fetchcustomer_paymentsAsStream(),
       builder: (context,snapshot) {
         if (snapshot.hasData) {
            List<Customer_payment_details> customers_information= snapshot.data;

           return ListView.builder(
             itemCount: customers_information.length,
             itemBuilder: (context, index){

               return YourCardClass(
                               customers_information: customers_information[index]);

}


stream:productProvider.fetchcustomer\u paymentsAsStream(),
生成器:(上下文,快照){
if(snapshot.hasData){
列出客户信息=snapshot.data;
返回ListView.builder(
itemCount:customers\u information.length,
itemBuilder:(上下文,索引){
归还你的信用卡(
客户信息:客户信息[i]
       stream:   productProvider.fetchcustomer_paymentsAsStream(),
       builder: (context,snapshot) {
         if (snapshot.hasData) {
            List<Customer_payment_details> customers_information= snapshot.data;

           return ListView.builder(
             itemCount: customers_information.length,
             itemBuilder: (context, index){

               return YourCardClass(
                               customers_information: customers_information[index]);

}