# #firebase #flutter #dart
Вопрос:
Когда я добавляю следующий код, я получаю сообщение об ошибке
W/Firestore(10073): (23.0.4) [Firestore]: Прослушивание запроса(цель=Запрос(исключение по имени);Тип ограничения=LIMIT_TO_FIRST) ошибка: Статус{код=РАЗРЕШЕНИЕ_ДАНО, описание=Отсутствуют или недостаточно разрешений., причина=null}
rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /exc/{uid}/{document=**}{ allow read, write: if request.auth.uid == uid; } } }
. .. ... Row( children: lt;Widgetgt;[ Expanded( child: _buildContents(context), ), ], ), ... Widget _buildContents(BuildContext context) { final database = Provider.oflt;Databasegt;(context, listen: false); return StreamBuilderlt;Listlt;Profilegt;gt;( stream: database.profilesStream(), builder: (context, snapshot) { if (snapshot.hasData) { final profiles = snapshot.data; final children = profiles.map((profile) =gt; Text(profile.nickname)).toList(); return ListView(children: children); } return Center(child: CircularProgressIndicator()); }, ); }
Это моя база данных.dart, которую я использую
abstract class Database { Futurelt;voidgt; createProfile(Profile profile); Streamlt;Listlt;Profilegt;gt; profilesStream(); } class FirestoreDatabase implements Database { FirestoreDatabase({@required this.uid}) : assert(uid != null); final String uid; Futurelt;voidgt; createProfile(Profile profile) =gt; _setData( path: APIPath.profile(uid, 'profile_abc'), data: profile.toMap(), ); Streamlt;Listlt;Profilegt;gt; profilesStream() { final path = APIPath.profiles(uid); final reference = FirebaseFirestore.instance.collection(path); final snapshots = reference.snapshots(); return snapshots.map((snapshot) =gt; snapshot.docs.map( (snapshot) { final data = snapshot.data(); return data != null ? Profile( nickname: data['nickname'], birthday: data['birthday'], ) : null; }, )); } Futurelt;voidgt; _setData({String path, Maplt;String, dynamicgt; data}) async { final reference = FirebaseFirestore.instance.doc(path); print('$path: $data'); await reference.set(data); } }
class APIPath { static String profile(String uid, String profileId) =gt; 'exc/$uid/'; static String profiles(String uid) =gt; 'exc/$uid/profiles'; }
Есть идеи, как это исправить?
Комментарии:
1. Вы создали коллекцию в firebase?
2. Какое имя в Firebase вы используете для своей коллекции профилей? /профиль? И как вы пытаетесь извлечь его в database.profilesStream()?
3. Я создал коллекцию в Firebase. Я отредактировал приведенный выше код и добавил дополнительную информацию