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
[cloud_firestore] Added Flutter web support #1670
Conversation
- Migrated DocumentReference and CollectionReference to use interfaces
- added where support
- fixed test failure causes
Feature/firestore web support
- use any as versions
Looping in @ditman @hterkelsen who have been working on similar functionality in #1633 |
Wow, thanks for doing this! I'm taking a look! |
No probs @ditman 👍 . It might fail builds on CI as packages such as The only thing that I am not unsure about is Let me know if you have anything. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amrfarid140 this is fantastic, I've been working with firestore for a while, and I appreciate the amount of work you put here!
I've added a bunch of comments but I didn't find anything major, (maybe other than the Transaction stuff, but I read that you're still working on getting that part tested).
I think we can get this merged with just a little bit of work. Let me know if you're interested in work on this PR some more!
packages/cloud_firestore/cloud_firestore/lib/cloud_firestore.dart
Outdated
Show resolved
Hide resolved
packages/cloud_firestore/cloud_firestore/lib/src/utils/PlatformUtils.dart
Outdated
Show resolved
Hide resolved
packages/cloud_firestore/cloud_firestore_platform_interface/CHANGELOG.md
Outdated
Show resolved
Hide resolved
packages/cloud_firestore/cloud_firestore_web/lib/transaction_web.dart
Outdated
Show resolved
Hide resolved
packages/cloud_firestore/cloud_firestore_web/lib/firestore_web.dart
Outdated
Show resolved
Hide resolved
packages/cloud_firestore/cloud_firestore_web/lib/firestore_web.dart
Outdated
Show resolved
Hide resolved
packages/cloud_firestore/cloud_firestore_web/lib/document_reference_web.dart
Outdated
Show resolved
Hide resolved
packages/cloud_firestore/cloud_firestore_web/lib/collection_reference_web.dart
Outdated
Show resolved
Hide resolved
@amrfarid140 Yes, there's also some failures on The toughest part to fix
What I did in PR was to leave the tests in the core package of the plugin, slightly modified to run with the new interface and make sure everything works (similar to the changes you have done when you moved the tests from the core to the platform_interface package. (I wasn't close to working in the Web plugin, so I didn't have a good story to test the web version!) (BTW, feel free to email me directly: dit at google if you need anything from me, I have time to help you with this). |
@amrfarid140 I cloned your fork, and modified it a little bit to run the example of the The error comes from the jsify util in It seems that the web types (maybe: 'DocumentReference', 'FieldValue', 'Blob', 'GeoPoint') need to extend the Firestore package types as well, look at
So close! |
@ditman ah ha! that did it!
I had that code in my thanks again! |
@erparker Glad you got it working! Programmatic initialization should be doable, but for now we're recommending the script tag method (which is what is also recommended by the Firebase console as well, so at least in that part we're identical to the JS SDK). |
One other strange thing I noticed - after adding firestore web and re-deploying my site, Chrome wouldn't display it and kept asking me if I wanted to install the PWA version of the app instead (which was just a blank screen as well). I removed firestore web from the project, re-deployed, and things were fine again. |
@erparker there was some weird interplay between Flutter web's service worker and the firestore requests that got solved a few days ago. Can you try upgrading your flutter channel to Note, that in that blank-screen case, you should look for clues/errors in the Javascript DevTools console, if any. |
Things are working again. I was already on latest Flutter,
I removed it on a whim since that issue you linked talked about a service worker, and it got things moving again. To be honest, I don't know what the service worker does, so no idea if removing it was a bad thing ¯_(ツ)_/¯ but things are running again with firestore_web in the project |
You dropped something: \
Service workers help manage the website even when the client is offline, along with other stuff browser-related. |
packages/cloud_firestore/cloud_firestore_web/lib/field_value_factory_web.dart
Outdated
Show resolved
Hide resolved
Merged and published cloud_firestore 0.13.2 with web support! Thanks @amrfarid140 for the super hard work!! |
Really? I'm going to test this out! |
All you need to depend on your App's pubspec, with a fairly recent version of flutter, is:
No need to specify dependencies on |
For a quick test, the |
So not yet on flutter's stable channel, but dev channel? |
@bean5 I normally use |
It's amazing to see this getting merged 😄 . Thanks so much @ditman and @collinjackson for your feedback and effort in this as well. |
So...I thought this meant that firebase_auth would be supported for web as well. Is that correct or can you use firestore without auth? |
@bean5 you can use firestore without using auth. Also, Auth supports web as well. |
Note: In a separate PR I've updated cloud_firestore and cloud_firestore_web documentation with the latest setup instructions, and marked "Web?" as supported in the main flutterfire contents matrix. |
I got it working. My firebase_auth package was pretty old and I was using old methods of serving web. Flutter web has come a long way since I ran into this issue. Thanks for the great fix! |
Anybody else start getting this error when running their flutter web app with cloud_firestore_web? I'm using this in my pubspec
When I run the app I just got a blank Chrome page and this in the javascript console:
It sort of looks like instantiating a new cloud firestore will call out to see what the operating system is, which is not allowed on flutter web. here's
Any ideas? |
@erparker Very odd, it seems like you are getting the configurable import for Dart VM even though you're running on web. How exactly are you running your app? BTW you don't need the |
@hterkelsen thanks for the quick reply! I've updated Flutter and the AS Flutter tools recently and I've had it working since then. FWIW here is my flutter doctor (the android warning has been there for over a year, I mainly build to iOS so I've ignored it)
|
@erparker please open a new github issue, we're spamming a bunch of people who may not be willing or able to help :) I'm going to lock conversation in this PR, it has run its course! Thanks all! |
Closing the loop on this @amrfarid140. I asked in our internal "Stack Overflow"-like system, and an engineer from the Cloud Firestore Data Plane team just confirmed that this was, indeed, a bug:
Nice! |
Description
cloud_firestore_platform_interface
to host A common platform interface for the cloud_firestore plugin.cloud_firestore_web
to host the web implementation for Firestorecloud_firestore
implementation to delegate tomethod_channel_xyz
incloud_firestore_platform_interface
when necessarycloud_firestore
tocloud_firestore_platform_interface
This PR is created for gathering feedback on the approach and check mergeability.
Todo items
This PR is created for gathering feedback on the approach. The remaining steps are
cloud_firestore_platform_interface
cloud_firestore_web
cloud_firestore
to use published version ofcloud_firestore_web
&cloud_firestore_platform_interface
cloud_firestore_web
cloud_firestore
delegates method calls to delegatecloud_firestore_platform_interface
FirebasePlatform._instance
initialisation until it's called for the first time (lazy init)DocumentReference
Transaction
WriteBatch
Related Issues
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?