Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

flutter firestore query

// this query gets a stream of user records and deserialize it 
// to a stream of UserRecord object 

FirebaseFirestore.instance.collection('users')
    .where('uid', isEqualTo: FirebaseAuth.instance.currentUser!.uid)
    .snapshots()
    .map((e) =>
        UserRecord.fromJson(e.docs.first.data() as Map<String, dynamic>))
Comment

firestore search query flutter

import 'package:flutter/material.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:firebase_database/ui/firebase_animated_list.dart';

class Db extends StatefulWidget {
  @override
  HomeState createState() => HomeState();
}

class HomeState extends State<Db> {
  List<Item> Remedios = List();
  Item item;
  DatabaseReference itemRef;
  TextEditingController controller = new TextEditingController();
  String filter;

  final GlobalKey<FormState> formKey = GlobalKey<FormState>();

  @override
  void initState() {
    super.initState();
    item = Item("", "");
    final FirebaseDatabase database = FirebaseDatabase.instance; //Rather then just writing FirebaseDatabase(), get the instance.
    itemRef = database.reference().child('Remedios');
    itemRef.onChildAdded.listen(_onEntryAdded);
    itemRef.onChildChanged.listen(_onEntryChanged);
    controller.addListener(() {
  setState(() {
    filter = controller.text;
  });
});
  }

  _onEntryAdded(Event event) {
    setState(() {
      Remedios.add(Item.fromSnapshot(event.snapshot));
    });
  }

  _onEntryChanged(Event event) {
    var old = Remedios.singleWhere((entry) {
      return entry.key == event.snapshot.key;
    });
    setState(() {
      Remedios[Remedios.indexOf(old)] = Item.fromSnapshot(event.snapshot);
    });
  }

  void handleSubmit() {
    final FormState form = formKey.currentState;

    if (form.validate()) {
      form.save();
      form.reset();
      itemRef.push().set(item.toJson());
    }
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
        centerTitle: true,
        backgroundColor: new Color(0xFFE1564B),
      ),
      resizeToAvoidBottomPadding: false,
      body: Column(
        children: <Widget>[
          new TextField(
          decoration: new InputDecoration(
          labelText: "Type something"
          ),
          controller: controller,
          ),
          Flexible(
            child: FirebaseAnimatedList(
              query: itemRef,
              itemBuilder: (BuildContext context, DataSnapshot snapshot,
                  Animation<double> animation, int index) {
                return  Remedios[index].name.contains(filter) || Remedios[index].form.contains(filter) ? ListTile(
                  leading: Icon(Icons.message),
                  title: Text(Remedios[index].name),
                  subtitle: Text(Remedios[index].form),
                ) : new Container();
              },
            ),
          ),
        ],
      ),
    );
  }
}

class Item {
  String key;
  String form;
  String name;

  Item(this.form, this.name);

  Item.fromSnapshot(DataSnapshot snapshot)
      : key = snapshot.key,
        form = snapshot.value["form"],
        name = snapshot.value["name"];

  toJson() {
    return {
      "form": form,
      "name": name,
    };
  }
}
Comment

PREVIOUS NEXT
Code Example
Python :: python decorator class 
Python :: python string: .title() 
Python :: pytest use fixture without running any tests 
Python :: python read array line by line 
Python :: python try except print error 
Python :: pandas sum 
Python :: python exit if statement 
Python :: python sort based on multiple keys 
Python :: remove element from a list python 
Python :: how to import packages in python 
Python :: import from parent directory in python setup 
Python :: Restrict CPU time or CPU Usage using python code 
Python :: “Python unittest Framework 
Python :: django cache framework 
Python :: python array empty 
Python :: Python - How To Convert String to ASCII Value 
Python :: if lower: --- 71 doc = doc.lower() 72 if accent_function is not None: 73 doc = accent_function(doc) 
Python :: python find in string 
Python :: Missing Data Plotly Express px.data 
Python :: wrds in python 
Python :: export ifc dataframe python 
Python :: pubmed database python 
Python :: python quickly goto line in file 
Python :: python multiply numbers nested list 
Python :: kali linux run python script anywhere 
Python :: python monats liste 
Python :: counter vectriozer in python 
Python :: sss 
Python :: splitting x,y using iloc 
Python :: controlliing a fill pattern in matplotlib 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =