Flutter RevenueCat SDK not working on web - flutter

For my flutter IOS/Android app i use https://pub.dev/packages/purchases_flutter ( RevenueCat ) to manage subscription and it's working perfectly well.
Now i want to export my flutter into a webapp using : Flutter build web
I got that error :
''No implementation found for method setupPurchases on channel purchases_flutter''
That's because purchases_flutter is not made for webapp for now.
My question:
I really need to export my application into a webapp, is there a way i can avoid that kind of error? Can i trick my code to skip every part that refer to that package?

I found that you can put a condition before initializing revenuecat plugin so if you are on the web it skip that part and the application can build correctly
To check if you are on web
import 'package:flutter/foundation.dart' show kIsWeb;
if (kIsWeb) {
// running on the web!
} else {
// NOT running on the web! You can check for additional platforms here.
}

Related

How does one properly add and enable firebase_auth in a flutter web app?

I am trying to add and enable firease_auth on flutter web. I have already added the web app on firebase, copied and pasted the required lines of code into web/index.html. I have added firebase_core and firebase_auth on pubspec.yaml and added the imports accordinly in my .dart files. I have added a user manually with their email and password on firebase. Now when I try to login from my web app, it always fails in main, it does not even launch. Here is what my main looks like:
Future<void> main() async
{
await Firebase.initializeApp(); // always fails here when trying to use firebase. it wont even launch.
runApp(const MyApp());
}
I have also used the same code base to make an android app and it works just fine. What might be the problem?
Initializing Firebase requires some configuration data about your project, so that the app can find that project on the servers. It needs this config on all platforms, but the native SDK for each platform has its own way of handling it.
If the same code works on Android, that means that you've included a google-services.json file into your Android Runner app, where the library then reads the config from.
In the web version, you'll typically include the config in the HTML file as shown in this older documentation on manually initializing Firebase in your Flutter web app.
Since having to do this different for each platform was confusing to many Flutter devs, there is now also a way to initialize from within the Flutter code itself - which is the same across all platforms. For more on this, see the current Firebase documentation on configuring Firebase in your Flutter app;

Already using sqflite database for mobile App which is not supporting to WebApp,can i use different library for web App in same if yes than which lib

i am using sqflite library for database but it is supporting to IOS/Android app can i use to database for App existing one(Sqflite) and for webApp different in the same app if I can then how and which will be the best.Thanks
Yes. You can use a separate package for the web. Now, to check whether your app is running on web or not:
import 'package:flutter/foundation.dart' show kIsWeb;
if (kIsWeb) {
// running on the web!
} else {
// NOT running on the web! You can check for additional platforms here.
}
If your use-case is just to store small values, you can use shared_preferences which is supported for both web and mobile.
You can also try hive which is supported for both.

How to check if flutter web app has been installed on the device?

I am using flutter web to make a web app, and I want to know whether the user has actually installed the web app or whether the web app is being run on a browser..
I want to know this so I can allow special features to users that have installed the web app in their devices. (e.g allow local_notifications which is not possible for flutter running on a browser)
Use JavaScript. Insert this HTML code to your index.html
<script>
function isPwaInstalled() {
return window.matchMedia('(display-mode: standalone)').matches;
}
</script>
Then in your dart file
import 'dart:js' as js;
bool isPwaInstalled() => js.context.callMethod("isPwaInstalled");
When your PWA app is installed to desktop this method will return true.
Note that the dart:js lib is available only on Flutter web, if you import it on other platforms such as iOS or Android, the compiler will complains about it. To avoid this, see Conditional Import or this blog
Adding a Safari Shortcut from a WebApp to HomeScreen is nothing like installing it. It just opens your WebApp in Safari browser
You won't know the difference with normal viewing of your WebApp
You can check the device with platform_detect 2.0.0 package thought but that's about it
Link to package https://pub.dev/packages/platform_detect

Can I disable a specific dependency for Flutter web?

I'm usingAdMob and Google Mobile Ads package for my flutter app and it works fine on iOS and Android, but as I understood it can't be used on flutter web and when I try to run my code on web it throws an exception for that dependency not being initialized. Is there a way to disable that dependency only for Flutter web? Or if there is a way to implement Google Ads on web?
Thank you
You can do something like below
import 'package:flutter/foundation.dart' show kIsWeb;
if (kIsWeb) {
// Do nothing
} else {
// Init Your dependency
}

Flutter Image picker for web and mobile

I need to develop a cross platform app using flutter that supports mobile as well as web platforms. I need an image picker that works for mobile as well as web. Currently I am using image picker flutter plugin for mobile and flutter_web_image_picker for web. But the build fails as flutter_web_image_picker uses dart:HTML and it is not supported for mobile builds. I need to know that how shall I conditionally render web pickers for their respective platforms as having two separate code bases won't make any sense?
Might be very late, but this is how we can execute any code conditionally for different platforms in flutter.
import 'package:flutter/foundation.dart' show kIsWeb;
Then in the function code -
if(kIsWeb){
... web specific code
} else {
... mobile specific code
}