import 'package:flutter/material.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; void main() => runApp(new MyApp()); class MyApp extends StatelessWidget { const MyApp(); @override Widget build(BuildContext context) { return new MaterialApp( title: 'Baby Names', home: const MyHomePage(title: 'Baby Name Votes'), ); } } class MyHomePage extends StatelessWidget { const MyHomePage({Key key, this.title}) : super(key: key); final String title; @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar(title: new Text(title)), body: new StreamBuilder( stream: Firestore.instance.collection('baby').snapshots(), builder: (context, snapshot) { if (!snapshot.hasData) return const Text('Loading...'); print(snapshot.data.documents); print(snapshot.hasData); print(snapshot.data.documents.length); return new ListView.builder( itemCount: snapshot.data.documents.length, padding: const EdgeInsets.only(top: 10.0), itemExtent: 25.0, itemBuilder: (context, index) { DocumentSnapshot ds = snapshot.data.documents[index]; return new Text(" ${ds['name']} ${ds['votes']}"); } ); }), ); } }
(edited)// Allow read/write access on all documents to any user signed in to the application service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read, write: if request.auth.uid != null; } } }