Does anyone have a example for using the 'where' in the snapshot for FirebaseFirestore?
As I want to listen to the documents where one of the fields are equal to a specific email.
This I want then to use to update my Scaffold to display the current settings.
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
class Test2 extends StatelessWidget {
const Test2({Key? key}) : super(key: key);
static const String id = 'test_2';
final TextEditingController _deviceName = TextEditingController();
final TextEditingController _onHour = TextEditingController();
@override
var firebaseUser = FirebaseAuth.instance.currentUser?.email;
final CollectionReference _device =
FirebaseFirestore.instance.collection('devices').where('email', isEqualTo: '$firebaseUser') as CollectionReference<Object?>;
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(leading: null,
actions: [
IconButton(
onPressed: () {},
icon: Icon(Icons.close))
],
title: const Text('Device Selection page'),),
body: StreamBuilder(
stream: _device.snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> streamSnapshot) {
if (streamSnapshot.hasData) {
return ListView.builder(
itemCount: streamSnapshot.data!.docs.length,
itemBuilder: (context, index) {
final DocumentSnapshot documentSnapshot = streamSnapshot.data!
.docs[index];
return Card(
margin: const EdgeInsets.all(10),
child: ListTile(
title: Text(documentSnapshot['deviceName']),
subtitle: Text(documentSnapshot['startHour'].toString()),
trailing: SizedBox(
width: 100,
child: Row(
children: [IconButton(
onPressed: () {}, icon: const Icon(Icons.edit)),
IconButton(onPressed: () {},
icon: const Icon(Icons.delete))
],
),
),
),
);
},);
};
return Container(
child: Row(
children: [Text('Test')],
),
);
},
)
);
}
}
