Flutter TabBarView和Firestore

时间:2020-07-25 00:57:21

标签: firebase flutter google-cloud-firestore

我在Tabbarview中有3个流构建器,其中包含来自Firestore的流,我只是想知道如何避免每次更改标签时都重新构建列表。

侧面问题:如果重建无济于事,重建物是否会从Firebase重新读取,这会产生更多读取费用?

代码:

SliverFillRemaining(
  child: TabBarView(
    children: [
      StreamBuilder<List<Job>>(
        initialData: [],
        stream: APIs().jobs.sJobsRecent(userID: user.user.userID),
        builder: (context, snapshot) {
          print('Recent Query');
          if (snapshot.hasError) {
            Funcs.logger(snapshot.error);
            return Container();
          } else {
            return snapshot.hasData ? AvailablePage(jobs: snapshot.data) : PAIndicator();
          }
        },
      ),
      user.user.seeker.resume != null
          ? StreamBuilder<List<Job>>(
              initialData: [],
              stream: APIs().jobs.sJobsMatched(seeker: user.user.seeker),
              builder: (context, snapshot) {
                print('Matched Query');
                if (snapshot.hasError) {
                  Funcs.logger(snapshot.error);
                  return Container();
                } else {
                  return snapshot.hasData ? AvailablePage(jobs: snapshot.data) : PAIndicator();
                }
              },
            )
          : Container(),
      StreamBuilder<List<Job>>(
        initialData: [],
        stream: APIs().jobs.sJobsApplied(userID: user.user.userID),
        builder: (context, snapshot) {
          print('Applied Query');
          if (snapshot.hasError) {
            Funcs.logger(snapshot.error);
            return Container();
          } else {
            List<Job> jobs = snapshot.data;
            jobs.sort((a, b) => b.updatedAt.compareTo(a.updatedAt));
            return snapshot.hasData ? AppliedPage(jobs: jobs) : PAIndicator();
          }
        },
      ),
    ],
    controller: this._tabController,
    physics: BouncingScrollPhysics(),
  ),
),

0 个答案:

没有答案