Skip to content

Loading a Document from a passed Reference is broken #25

@atn832

Description

@atn832

Expected behavior (required)

When a view passes a Document reference to another view, I expect the other view to successfully load the document from the reference.

Current behavior (required)

I get an infinite spinner and the data never loads. No error is displayed either.

To Reproduce (required)

  1. I set up a first view with a ListView showing documents in a collection.
  2. I set up a second view which will show the selected document.
  3. In the first view, I set up the ListViewItem to navigate to the second view, and pass the document reference.
  4. In the second view, I set up the Scaffold to load a document based on the passed document reference.
  5. In the Scaffold, I have a Text widget which displays a field from the loaded document.

I am basically following the steps at:

Context (required)

I am trying to load a document from a passed reference.

Screenshots / recordings

Another user in the Discord channel was able to reproduce the bug: https://discord.com/channels/845826746582695976/845826825992929321/1027793029517545493.

To work around this issue, the solution they shared, which works for me too, is to pass the Document itself. Then in the second view, load the document again using the passed Document's reference.

I tried setting up two Text widgets, one using the passed reference, and the other reading the reference from the passed document. The first one shows an infinite spinner. The second one shows the data. I expected both to just show the same data (ie "bakeree").

image

The resulting code is nearly identical and seems correct:

              StreamBuilder<CompaniesRecord>(
                stream: CompaniesRecord.getDocument(widget.companyRef!),
                builder: (context, snapshot) {
                  // Customize what your widget looks like when it's loading.
                  if (!snapshot.hasData) {
                    return Center(
                      child: SizedBox(
                        width: 50,
                        height: 50,
                        child: CircularProgressIndicator(
                          color: FlutterFlowTheme.of(context).primaryColor,
                        ),
                      ),
                    );
                  }
                  final textCompaniesRecord = snapshot.data!;
                  return Text(
                    textCompaniesRecord.name!,
                    style: FlutterFlowTheme.of(context).bodyText1,
                  );
                },
              ),
              StreamBuilder<CompaniesRecord>(
                stream: CompaniesRecord.getDocument(
                    widget.passedCompany!.reference),
                builder: (context, snapshot) {
                  // Customize what your widget looks like when it's loading.
                  if (!snapshot.hasData) {
                    return Center(
                      child: SizedBox(
                        width: 50,
                        height: 50,
                        child: CircularProgressIndicator(
                          color: FlutterFlowTheme.of(context).primaryColor,
                        ),
                      ),
                    );
                  }
                  final textCompaniesRecord = snapshot.data!;
                  return Text(
                    textCompaniesRecord.name!,
                    style: FlutterFlowTheme.of(context).bodyText1,
                  );
                },
              ),

Your environment

  • Version of FlutterFlow used:

image

  • on a Mac Mini M1 in Chrome 105.0.5195.125 (arm64).

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions