How to use cloud_firestore in flutter for web and android? - flutter

I have a Flutter app which works on Android as expected but if I want to compile it for Web I get an error.
It has to do something with the dependency cloud_firestore. If I use the dependency firebase it works fine on the web but on android now not..
This is the error message I get using cloud_firestore (compiling for web):
Skipping compiling pay_balance|lib/main_web_entrypoint.dart with ddc because some of its
transitive libraries have sdk dependencies that not supported on this platform:
firebase_core|lib/firebase_core.dart
https://github.com/dart-lang/build/blob/master/docs/faq.md#how-can-i-resolve-skipped-compiling-warnings
Can anybody help me? Maybe with another dependency for firestore (I did not find others which are working on web and android)..
Edit: I have used the firebase-dart plugin for web!! -> Only works on the web but not in android for me -> I need something for both at the same time!!
Or is there a Way I can use both packages without getting a compling error for the web when I import cloud_firestore?

If you want to use Firebase on Web and Mobile you have to get creative. I created the fb_auth plugin that uses the Mobile SDK firebase_auth on iOS and Android and the firebase package on web. This will give you a single plugin for auth.
https://pub.dev/packages/fb_auth
Im working on firstore and storage but they are not ready yet.
I have also created an article on how to do this with flutter:
https://medium.com/#rody.davis.jr/how-to-build-a-native-cross-platform-project-with-flutter-372b9e4b504f
You have to use dynamic imports so that at compile time it tree shakes what it doesn't need and will not throw an error.
Currently this is the only way to officially use both plugins in the same project.

EDIT: cloud_firestore now added
Two of the FutterFire plugins are now supported for web. FlutterFire plugins supporting web firebase_auth and firebase_core
cloud_firestore is now also supported

Related

Error in Flutter while using Provider tool

I am building a basic app using flutter, in which I had to use provider, I added Provider dependencies in pubspec.yaml file but getting this error please help, I added the error below not able to fix this problem I have the latest flutter SDK
To solve this use lower version of Provider dependency as newer version of provider depends on newer version of Flutter SDK and your application's Flutter SDK is old one so it will have compatibility issues, So just degrade the version of dependency or you can also run pub outdated command and it will suggest you compatible version as per your SDK.

Audioplayer plugins using a deprecated version of the android embedding

I want to add Audioplayer package for my xylophone app but on running it, I get this following error:
The plugins audioplayers, path_provider use a deprecated version of
the Android embedding. To avoid unexpected runtime failures, or future
build failures, try to see if these plugins support the Android V2
embedding. Otherwise, consider removing them since a future release of
Flutter will remove these deprecated APIs. If you are plugin author,
take a look at the docs for migrating the plugin to the V2 embedding:
https://flutter.dev/go/android-plugin-migration.
I was having the same problem while using audioplayers library. So, after looking up on the internet I found out that I was using the old version of the dependency of audio player. So, I suggest you to check for the latest version of audioplayers library from https://pub.dev/packages/audioplayers, and add it in your dependency as
dependencies:
audioplayers: ^0.20.1
(For me it was 0.20.1). You can check for latest to avoid error. Hope it works for you.

Flutter | Error: Couldn't resolve the package

I created a package that is a collection of my own helper classes for faster developing...
The package also included firebase_analytics: which requires a native implementation for each platform i want it to run. Even if i dont wanted to use firebase at all, but still wanted to use my package i was forced to create firebase-config files for the app, because the app crashes if the firebase_analytics package does not find a valid file for the specific platform. To avoid those things i splitted my package in two packages.
The Core-Package: All helper classes that run native dart code
Optional extension: Only the classes that need the firebase implementation
So if i want to use the package without firebase i just have to depend on the core.
If i want to use the firebase variant i could simply depend the firebase package, because the extension package itself depends on the core-package in its own pubspec.yaml file.
PROBLEM: Since i restructured my package like i described, all my apps that depend on it are not building anymore. The console says that all packages that i depend on in my two packages can not be found. This error occures both ways: With firebase & without.
ERROR: (Scroll down for the complete console output)
MY ATTEMPTS:
"flutter clean" & "flutter pub get" in every package and app folder
"flutter pub cache repair"
CORE-PACKAGE Pubspec.yaml:
FIREBASE-Extension Pubspec.yaml:
Plain Console Output:
pastebin.com/m14cbqDV
Thanks for any help!!
I am facing the same issue while i was making a build in Xcode 13.So I had upgraded my flutter version 2.8.0 to 2.10.2 and also removed the version of all firebase dependencies, then the issue was finally solved.
I have faced similar issues and resolved them by removing package versions. Issues like this often arise due to mismatched versions of packages (eg firebase_core, firebase analytics). Please try to remove versions of the firebase packages or the whole packages. (like firebase_analytics :).
Sorry, my bad! As you can see i moved my dependencys to the dev section of my pubspec.yaml. They should be placed in the dependency section.

How do you integrate a flutter plugin into an existing flutter project?

I want to install a simple audio recorder which will record a user’s voice. I know I can find plugins on PubDev, however I have difficulty in integrating them into my Flutter project. I have installed ‘audio_recorder 1.0.2. in a new dart file as part of ‘lib’. I don’t know how to integrate this file into the flutter project. I have tried to a button in another dart file which when pressed would take the user to that file, without succes. ‘This class is not a widget’ is the message I get. The ‘GitHub’ version has the errors ‘undefined class’, ‘LocalFileSystem isn’t defined for the type ‘AudioRecorder’. The example version (why this difference?) has quite a few errors after installation. Dependencies and imports are ok. When I install audio_recorder 1.0.2 inside the project via ‘Dart packages’ I get a lot of errors. I have successfully installed an audio recorder in another android app. I would like some help in how to integrate plugins in a flutter project.
The plugins have instructions on how to install it. Got to your pubspec.yaml-file and put it under dependencies.
Make sure that you add your dependency to pubspec.yaml like this:
dependencies:
audio_recorder: ^1.0.2
After that make sure to type "flutter pub get" in console.
Go on a specified file in which you want to use Your dependency and import it like this:
import 'package:audio_recorder/audio_recorder.dart';

Flutter Web cloud_firestore package: Versions newer than 0.12.11 produces just a blank web page

When I run the command: flutter build web => I get a blank web page. If I use cloud_firestore::0.12.11 OR older, all runs perfectly well.
Steps to reproduce the behavior:
flutter doctor. No issues found.
flutter run -d chrome. The app runs OK on the local browser.
flutter build web. The app runs and shows a blank page.
In pubspec.yaml: remove the dependency cloud_firestore: The app runs OK.
In pubspec.yaml: add the dependency cloud_firestore:0.12.11 (older version), The app runs OK.
Expected behavior
I need to use cloud_firestore: 0.14.0+2 so I can use the data type FirebaseFirestore.
Are you also using other firebase packages? I have found there are issues with firebase_auth - including a black screen.
Make sure you following the Migration Guide: https://firebase.flutter.dev/docs/migration/#plugin-changes
The issue was with a bug in the library itself.