Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase in realtime from StreamBuilder through different pages? #12

Closed
enri90 opened this issue Apr 11, 2020 · 5 comments
Closed

Firebase in realtime from StreamBuilder through different pages? #12

enri90 opened this issue Apr 11, 2020 · 5 comments
Labels
question Further information is requested

Comments

@enri90
Copy link

enri90 commented Apr 11, 2020

How to share data firebase in realtime from StreamBuilder through different pages?

EntryPage.show( context: context, job: job )

in the second screen am I forced to recall firebase?

@bizz84
Copy link
Owner

bizz84 commented Apr 13, 2020

@enri90 I'm not sure if this is the right example.
EntryPage doesn't use a StreamBuilder at all.
It just takes the job that was given as an argument, and uses it to prefill the text inputs.
Then it saves the data back to Firebase at the end.

@bizz84 bizz84 added the question Further information is requested label Apr 13, 2020
@fabads
Copy link

fabads commented Apr 20, 2020

Hello,

First of all I would like to really thank you @bizz84 for this great source of inspiration. I'm learning Flutter and try to convert an Android Java app to this new framework using your canvas.

I think I have a similar question to @enri90. As you set user available on top of the widget tree, I would like to have associated user data (stored in the database) available to all widgets of my app. What would be your advice ?

An example: the app manages a list of jobs and the user can select the job to be displayed by default when he opens the app. In the database I have the list of jobs and userData document containing a field selectJob equals to the ID of the job.

@fabads
Copy link

fabads commented Apr 20, 2020

To complement my post above, here an example of the solution I used to customize a selected element in a navigation drawer, but each time I need to nest streambuilder to get the data itself and the user preferences (or whatever):

 return StreamBuilder<UserData>(
      stream: database.userDataStream(),
      builder: (context, userDataSnapshot) {
        return StreamBuilder<List<Job>>(
          stream: database.jobsStream(),
          builder: (context, snapshot) {
            return JobListBuilder<Job>(
              snapshot: snapshot,
              userDataSnapshot: userDataSnapshot,
              itemBuilder: (context, job, userData) =>
                  ListTile(
                    selected: userData.selectedJobId == job.id,
                    title: Text(job.name),
                    onTap: () {
                      database.setUserSelectedJob(job.id);
                      ExtendedNavigator.of(context).pop();
                      IrrigationPage.show(context, job);
                    },
                  ),
            );
          },
        );
      }
    );

@sbadisa
Copy link

sbadisa commented May 17, 2020

Not sure if I've understood the question correctly, but have you considered StreamProvider from the Provider package?

@bizz84
Copy link
Owner

bizz84 commented Jan 7, 2023

The project now uses realtime data with StreamProvider from the Riverpod package.

Closing following changes in #94.

@bizz84 bizz84 closed this as completed Jan 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants