StreamBuilder ИЛИ BlocBuilder для Firebase Firestore - PullRequest
0 голосов
/ 01 октября 2019

Я так озадачен блочным шаблоном и тем, как его интегрировать с Firebase. Как я должен использовать strambuilder, когда я использую шаблон блока или я должен использовать только blocBuilder? Я также добавил несколько комментариев через мой код, чтобы дать вам представление о том, что смущает меня

BlocBuilder(
          //should i put the whole bloc package here or the stream of the bloc only
          bloc: _searchBloc,
          builder: (context, bloc) {
            return StreamBuilder<QuerySnapshot>(
            // is this how am i supposed to get data from firestore with bloc pattern?
                stream: Firestore.instance.collection('Artists').snapshots(),
                builder: (BuildContext context,
                    AsyncSnapshot<QuerySnapshot> snapshot) {
                  if (snapshot.hasError)
                    return new Text('Error: ${snapshot.error}');
                  switch (snapshot.connectionState) {
                    case ConnectionState.waiting:
                      return new Text('Loading...');
                    default:
                      return new ListView(
                        shrinkWrap: true,
                        // here i want the list to be filtered from the value i get from the bloc
                        // however its showing errors because _searchBloc.outSearch is a stream and not a string
                        children: snapshot.data.documents
                            .where((document) => document['name']
                                .toString()
                                .toUpperCase()
                                .contains(_searchBloc.outSearch
                                    .toString()
                                    .toUpperCase()))
                            .map((DocumentSnapshot document) {
                          return SearchItem(
                            artist: Tools.getArtist(document),
                            widthSize: MediaQuery.of(context).size.width,
                            heightSize: Makeover.getVerticalSize(context),
                          );
                        }).toList(),
                      );
                  }
                });
          },
        ),
...