Firebase 在Flitter中的ListBuilder中的预构建列表上添加过滤器和搜索功能

Firebase 在Flitter中的ListBuilder中的预构建列表上添加过滤器和搜索功能,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,想要实现搜索功能,我的预建数据列表!但就是做不到! *旁注:我希望结果可以像现在在列表中一样进行编辑。 我还想按格式顺序把清单拿进来。。就像患者姓名从A开始到顶部一样 这是我的项目代码。如果需要,请要求更多 列出病人 import 'package:fireStoreApp/models/patient.dart'; import 'package:fireStoreApp/screens/modify_patients.dart'; import 'package:fireStoreApp/s

想要实现搜索功能,我的预建数据列表!但就是做不到! *旁注:我希望结果可以像现在在列表中一样进行编辑。 我还想按格式顺序把清单拿进来。。就像患者姓名从A开始到顶部一样

这是我的项目代码。如果需要,请要求更多

列出病人

import 'package:fireStoreApp/models/patient.dart';
import 'package:fireStoreApp/screens/modify_patients.dart';
import 'package:fireStoreApp/shared_contents/loading_cursor.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';


class PatientList extends StatefulWidget {
  @override
  _PatientListState createState() => _PatientListState();
}

class _PatientListState extends State<PatientList> {
  TextEditingController searchController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    //circle
    Widget bigCircle = new Container(
      width: 60.0,
      height: 60.0,
      decoration: new BoxDecoration(
        color: Colors.white,
        shape: BoxShape.circle,
      ),
    );
    
    //bringing in the stream
    final patients = Provider.of<List<Patient>>(context);
    var items = List<Patient>();

    @override
    void initState() {
      items.addAll(patients);

      super.initState();
    }

    return Scaffold(
      
      // displaying the retrieved lists.
      body: (patients != null)
          ? Column(
              children: [
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: TextField(
                    onChanged: (value) {},
                    controller: searchController,
                    decoration: InputDecoration(
                        labelText: "Search",
                        hintText: "Search",
                        prefixIcon: Icon(Icons.search),
                        border: OutlineInputBorder(
                            borderRadius:
                                BorderRadius.all(Radius.circular(50.0)))),
                  ),
                ),
                Expanded(
                  child: patients.length > 0
                      ? ListView.builder(
                          shrinkWrap: true,
                          itemCount: patients.length,
                          itemBuilder: (context, index) {
                            return ListTile(
                              //title
                              title: Container(
                                padding: EdgeInsets.all(2.0),
                                decoration: BoxDecoration(
                                  color: Colors.amber[800],
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(40)),
                                ),
                                child: Container(
                                  //name and pic container
                                  padding: EdgeInsets.all(2.0),
                                  decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(50)),
                                  ),
                                  child: Column(
                                    children: [
                                      Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceBetween,
                                        children: [
                                          //circle avatar for image
                                          Container(
                                            child: Row(
                                              children: [
                                                Stack(
                                                  children: [
                                                    bigCircle,
                                                    Positioned(
                                                      child: CircleAvatar(
                                                        //for image
                                                        backgroundColor:
                                                            Colors.green[100],
                                                        child: Text(
                                                          patients[index]
                                                              .patientName[0]
                                                              .toUpperCase(),
                                                          style: TextStyle(
                                                              color:
                                                                  Colors.black,
                                                              fontWeight:
                                                                  FontWeight
                                                                      .w500),
                                                        ),
                                                      ),
                                                      top: 0.0,
                                                      left: 0.0,
                                                      right: 0.0,
                                                      bottom: 0.0,
                                                    ),
                                                    Positioned(
                                                      child: Icon(
                                                        Icons.brightness_1,
                                                        color: Colors.red[
                                                            (patients[index]
                                                                .severityLevel
                                                                .toInt())],
                                                      ),
                                                      top: 0.0,
                                                      left: 40.0,
                                                      right: 10.0,
                                                      bottom: 40.0,
                                                    )
                                                  ],
                                                ),
                                                SizedBox(width: 10),
                                                //cutomername
                                                Text(
                                                  (patients[index].patientName),
                                                  style: TextStyle(
                                                    color: Colors.amber[900],
                                                    fontSize: 18.0,
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ),

                                          // View/ Edit Icon
                                          Container(
                                            //padding: EdgeInsets.all(7),
                                            decoration: BoxDecoration(
                                              //color: Colors.white,
                                              borderRadius:
                                                  BorderRadius.circular(50),
                                            ),
                                            //Builder
                                            child: Column(
                                              children: [
                                                Builder(
                                                  builder: (BuildContext
                                                      innerContext) {
                                                    return IconButton(
                                                      icon: Icon(Icons
                                                          .more_horiz), 
                                                      color: Colors.black,
                                                      iconSize: 28.0,
                                                      onPressed: () {
                                                        Navigator.of(context)
                                                            .push(
                                                          MaterialPageRoute(
                                                            builder: (context) =>
                                                                EditPatients(
                                                              patients[index],
                                                            ),
                                                          ),
                                                        );
                                                      },
                                                    );
                                                  },
                                                ),
                                              ],
                                            ),
                                          ),
                                        ],
                                      ),
                                    ],
                                  ),
                                ),
                              ),
                              //other details info
                              subtitle: Container(
                                padding: EdgeInsets.all(10),
                                decoration: BoxDecoration(
                                  color: Colors.transparent,
                                  
                                  borderRadius: BorderRadius.only(
                                      bottomRight: Radius.circular(10),
                                      bottomLeft: Radius.circular(10)),
                                ),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  
                                  children: [
                                    Text(
                                        ((patients[index].patientContact) +
                                            (' | ') +
                                            (patients[index].patientAddress)),
                                        style: TextStyle(
                                            color: Colors.black,
                                            fontSize: 16.0)),
                                    SizedBox(height: 5),
                                    Row(
                                      children: [
                                        Text(('Remarks : '),
                                            style: TextStyle(
                                                color: Colors.orange[700],
                                                fontSize: 14.0)),
                                        Expanded(
                                          child: Text(
                                              (patients[index]
                                                  .patientHealthStatus),
                                              style: TextStyle(
                                                  color: Colors.black,
                                                  fontSize: 14.0)),
                                        ),
                                      ],
                                    ),
                                    Row(
                                      children: [
                                        Text('Supplements : ',
                                            style: TextStyle(
                                                color: Colors.green[700],
                                                fontSize: 14.0)),
                                        Expanded(
                                          child: Text(
                                              (patients[index].supplements),
                                              style: TextStyle(
                                                  color: Colors.black,
                                                  fontSize: 14.0)),
                                        ),
                                      ],
                                    ),
                                    
                                    Divider(),
                                  ],
                                ),
                              ),

                              onTap: () {
                                Navigator.of(context).push(MaterialPageRoute(
                                    builder: (context) =>
                                        EditPatients(patients[index])));
                              },
                            );
                          },
                         
                        )
                      : LoadingCursor(),
                ),
              ],
            ) 
          : LoadingCursor(),
    );
  }
}

病人,飞镖


class Patient {
  final String patientID;
  final String patientName;
  final String patientAddress;
  final String patientContact;
  final String patientHealthStatus;
  final double severityLevel;
  final String supplements;
  final String searchKey;

  // creating constructor.
  Patient({
    this.patientID,
    this.patientName,
    this.patientAddress,
    this.patientContact,
    this.patientHealthStatus,
    this.severityLevel,
    this.supplements,
    this.searchKey,
  });

  Map<String, dynamic> toMap() {
    return {
      'patientID': patientID,
      'patientName': patientName,
      'patientAddress': patientAddress,
      'patientContact': patientContact,
      'patientHealthStatus': patientHealthStatus,
      'severityLevel': severityLevel,
      'supplements': supplements,
      'searchKey': searchKey,
    };
  }

  Patient.fromFirestore(Map<String, dynamic> firestore)
      : patientID = firestore['patientID'],
        patientName = firestore['patientName'],
        patientAddress = firestore['patientAddress'],
        patientContact = firestore['patientContact'],
        patientHealthStatus = firestore['patientHealthStatus'],
        severityLevel = firestore['severityLevel'],
        supplements = firestore['supplements'],
        searchKey = firestore['searchKey'];
}


班级病人{
最终字符串patientID;
最终字符串patientName;
最后一条裙子;
最后一个字符串patientContact;
最终字符串状态;
最终双严重级别;
最终字符串补充;
最终字符串搜索键;
//创建构造函数。
病人({
这是我的,
这是我的名字,
这件衣服,
这个.病人接触,,
这是一种精神状态,
这个,严重级别,
这是我的补充,
这是我的搜索键,
});
映射toMap(){
返回{
“patientID”:patientID,
“patientName”:patientName,
“patientAddress”:patientAddress,
“patientContact”:patientContact,
“PatientThealthStatus”:PatientThealthStatus,
“严重级别”:严重级别,
"补充":补充,,
“searchKey”:searchKey,
};
}
患者。来自firestore(地图firestore)
:patientID=firestore['patientID'],
patientName=firestore['patientName'],
patientAddress=firestore['patientAddress'],
patientContact=firestore['patientContact'],
PatientThealthStatus=firestore['PatientThealthStatus'],
severityLevel=firestore['severityLevel'],
副刊=firestore[“副刊”],
searchKey=firestore['searchKey'];
}
消防队


import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fireStoreApp/models/patient.dart';

class FirestoreService {
  Firestore _db = Firestore.instance;

  Future<void> savePatient(Patient patient) {
    return _db
        .collection('patients')
        .document(patient.patientID)
        .setData(patient.toMap());
  } // this a call to add / update a product in firestore.

  // getter for all the patients in our app.
  Stream<List<Patient>> getPatients() {
    // to get future, .getDocuments(), to get stream, .snapshots()
    return _db.collection('patients').snapshots().map(
          (snapshot) => snapshot.documents
              .map((document) => Patient.fromFirestore(document.data))
              .toList(),
        );
  }

  //creating a delete fn.
  Future<void> removePatient(String patientID) {
    return _db.collection('patients').document(patientID).delete();
  }
}


导入“包:cloud_firestore/cloud_firestore.dart”;
导入“包:fireStoreApp/models/patient.dart”;
类别消防服务{
Firestore _db=Firestore.instance;
未来患者(患者){
返回_db
.收集(“患者”)
.document(patient.patientID)
.setData(patient.toMap());
}//这是在firestore中添加/更新产品的调用。
//getter适用于我们应用程序中的所有患者。
病人人数({
//要获取未来,.getDocuments(),要获取流,.snapshots()
返回_db.collection('patients').snapshots().map(
(快照)=>snapshot.documents
.map((document)=>Patient.fromFirestore(document.data))
.toList(),
);
}
//创建删除fn。
未来移除患者(字符串patientID){
返回_db.collection('patients').document(patientID.delete();
}
}
一个谦虚的请求来指引我。切尔斯


import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fireStoreApp/models/patient.dart';

class FirestoreService {
  Firestore _db = Firestore.instance;

  Future<void> savePatient(Patient patient) {
    return _db
        .collection('patients')
        .document(patient.patientID)
        .setData(patient.toMap());
  } // this a call to add / update a product in firestore.

  // getter for all the patients in our app.
  Stream<List<Patient>> getPatients() {
    // to get future, .getDocuments(), to get stream, .snapshots()
    return _db.collection('patients').snapshots().map(
          (snapshot) => snapshot.documents
              .map((document) => Patient.fromFirestore(document.data))
              .toList(),
        );
  }

  //creating a delete fn.
  Future<void> removePatient(String patientID) {
    return _db.collection('patients').document(patientID).delete();
  }
}