url_launcher throws MissingPluginException on flutter web after deployment - firebase

I want to open the system's email program from the browser and I do this by calling
TextSpan(
text: 'support#company.de',
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.bold,
),
recognizer: TapGestureRecognizer()
..onTap = () async {
await launchUrl(
Uri(
scheme: 'mailto',
path: 'support#company.de',
),
);
})
When I test the code locally (also with --release builds) everything works fine but as soon as I deploy the app to firebase hosting it returns an
Uncaught Error: MissingPluginException(No implementation found for method launch on channel plugins.flutter.io/url_launcher)
What's the difference between my local release builds and the one I upload to firebase hosting?
Why does it suddenly give me this MissingPluginException?

I encountered the same problem. Adding url_launcher_web as a dependency in my pubspec file solved the issue for me.
flutter pub add url_launcher_web

Related

google cloud function deploying failed functions: cleaning up build files

when i tried to deployed the cloud functions. i am facing the error below..
before update the node version it was working fine
node#14
firebase cli up-to date
nom also up-to date
const functions = require('firebase-functions')
const admin = require('firebase-admin');
const nodemailer = require('nodemailer');
const cors = require('cors')({ origin: true });
admin.initializeApp()
exports.sendcertificate = functions.firestore.document('certificate/{docId}')
.onCreate((snap: { data: () => any; }, ctx: any) => {
const data = snap.data();
let authData = nodemailer.createTransport({
host: 'mail.bacttraining.com',
port: 465,
secure: true, // use SSL
auth: {
user: *******',
pass: *******',
},
});
authData.sendMail({
from: ********,
to: *********,
Bcc: '*******',
sender: "*******",
subject: "Certificate Request",
text: `${data.course}`,
html: *******,
}).then(console.log("email send sussfully"))
.catch(console.error('we cant send email : ', console.error()
));
}
);**strong text**
Make sure your CLI tools are up to date, and that your modules in use are the latest. I can see that the console is warning you that cloud functions are outdated.
Then ensure all functions that did not deploy for any bugs and syntax errors as the cloud functions uploader can crash if the code was packed incorrectly.
Once the above has been done, you can try deploying the functions one at a time with
firebase deploy --only functions:functionName
This will narrow any functions that have bugs or syntax errors down.
This issue occurs when there is difference in the node version you have installed in the system and the node engine version mentioned in package.json file.
Please check your node version using
node -v
Make sure you have mentioned the same engine version in package.json

Unable to load image from Firebase Storage using Flutter Image Network

I created dummy list of items in my Firestore and stored an image in my storage.
Here's my code for reading the Image form
child: ListView.separated(
itemBuilder: (context, int index) {
return ListTile(
leading: Image.network(
itemNotifier.itemList[index].imageURL),
width: 100.0,
height: 100.0,
),
title: Text('${itemNotifier.itemList[index].name}'),
subtitle: Text(
'${itemNotifier.itemList[index].description}',
maxLines: 2,
),
trailing: Text(
'${itemNotifier.itemList[index].price.toString()}',
),
);
The error I get when I try viewing this items List page is as below:
════════ Exception caught by image resource service ════════════════════════════════════════════════
The following NetworkImageLoadException was thrown resolving an image codec:
HTTP request failed, statusCode: 404, http://(db-name).appspot.com/images/pablo-downloading.png
When the exception was thrown, this was the stack:
#0 NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:95:9)
#1 NetworkImage.load (package:flutter/src/painting/_network_image_io.dart:48:14)
#2 ImageProvider.resolveStreamForKey. (package:flutter/src/painting/image_provider.dart:501:13)
#3 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:359:22)
...
Image provider: NetworkImage("http://(db-name).appspot.com/images/pablo-downloading.png", scale: 1.0)
Image key: NetworkImage("http://(db-name).appspot.com/images/pablo-downloading.png", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════
What could I be missing here? Is it normal to have the String for the image url to start with "gs://"? Do I have to encode and decode for reads and writes each time?
there are two urls generated for every image you upload to firebase storage
storage url (starting with gs://)
download url (starting with https://)
you need to use the download url
to get the download url in flutter you can refer the following block of code
StorageReference
firebaseStorageRef=FirebaseStorage.instance.ref().child('fileName');
var url = await firebaseStorageRef.getDownloadURL();
to get the download link from firebase storage UI console click on the image , a left dialog wil appear and right click on the blue underlined image name and click opean in new tab
reference
https://stackoverflow.com/a/41767410/11330119

How to stub external services in Firebase emulator?

I have one firestore trigger function that is creating DNS record based on the slug attribute. I have some unit tests where I am stubbing #google-cloud/dns module so no external HTTP request is made. However, I have several integration tests as well. Those are hitting local firebase emulator (localhost:8080).
For instance, whilst testing firestore rules, I am simply calling db.collection('path').add(model) and that is triggering callable function inside emulator process.
Tests are running by this command: firebase emulators:exec 'mocha --config spec/.mocharc.yml
At first, it is initializing emulators and then running tests. As far as I understood these are different processes. So inside the mocha process, I am able to stub, mock with modules. On the other hand, inside the emulator process, functions, modules, dependencies are already loaded as it is. So when I am running this test script for testing firestore rules inside mocha test suite:
await assertSucceeds(db.doc('stores').set(store));
It actually runs the handler and sends the request to the google cloud DNS. Did anyone face issues something like this? Thanks in advance.
I'm facing the same situation. My plan is to make the Cloud Function initialize itself with a stubbed service that will record its own calls to a log collection in Firestore when NODE_ENV=test. Then the test will check whether the call was recorded by querying that collection.
test('fanOutCategoryFields', async () => {
// Initialize Firebase and seed test data
const app = await setup({
'categories/1': {
name: 'Some Name',
},
'posts/1': {
categoryId: '1',
},
})
// Update a document (will trigger the Cloud Function)
await app
.firestore()
.collection('categories')
.doc('1')
.update({ name: 'New Name' })
// Wait for the Cloud Function to run
await new Promise(resolve => setTimeout(resolve, 3000))
// Query the collection where function calls are recorded
const calls = await app
.firestore()
.collection('_calls')
.get()
.then(snap => snap.docs.map(snap => snap.data()))
// Check if Algolia was called with the expected arguments
expect(calls).toEqual([
{
fn: 'algolia.update',
args: ['products', '1', { categoryName: 'New Name' }],
},
])
})

Cloud function exception in Flutter

I'm facing an issue after updating all my libraries to comply with AndroidX.
Specifically, when I try to use the package "cloud_functions", I receive this error message:
flutter: throwing generic exception
flutter: Exception: Unable to call function funName
Now, I didn't touch the code handling the call, I simply updated the packages in the yaml file.
My code is:
cfResponse = await CloudFunctions.instance.call(
functionName: 'funName',
parameters: {
"p1": p1,
"p2": p2,
},
).then((response) {
return response;
}).catchError((error) {
print(error);
return null;
});
I'm having the same issue both on Android and iOS.
My libraries are at version:
- cloud_functions: ^0.1.1
- firebase_auth: ^0.8.1+4
I'm on Flutter 1.2.1 and Dart 2.1.2
I ran into the same issue but only on iOS and came across cloud_functions bug. I manually set the region like the PR does and was able to get it to work. It looks like the fix will be in a coming release.

how to enable firebase notifications in ionic android application

i want to build an application and use firebase for notification done a lot of search over google but did not find any good guide and solution , everything i tried ended into some errors . i tried ionic docs but they are all messy after the ionic v4 they shows everything about v4 i have my app almost finished up just this thing remains .
i will appreciate any help .
Any idea how to proceed? I'm most probably not configuring Firebase properly. I have placed google-services.json in the root directory, no problems there. but after that its all out of my understanding
AN ERROR OCCURRED WHILE RUNNING ionic cordova plugin add phonegap-plugin-push --variable SENDER_ID-150482406038 --SAVE EXIT CODE 1
Got this Working . Thanks everyone for help!
refrences used-
https://ionicframework.com/docs/v3/native/push/
https://github.com/phonegap/phonegap-plugin-push
works for
ionic 3.20.1
cordova 8.1.2
steps i followed
Removed my android platform using ionic cordova platform
removeandroid then i created it agin ionic cordova platform add
android. just to avoid any errors which my be there with my old
android version.
Got the google-services.json and placed it in the
rootDirectoryOfApp\platforms\android\app
then i run $ ionic cordova plugin add phonegap-plugin-push $ npm
install --save #ionic-native/push#4
Edit config.xml look for <platform name="android"> under that i
wrote <resource-file src="google-services.json"
target="app/google-services.json" />
Edit package.json look for "phonegap-plugin-push" and edit it
something like this
"phonegap-plugin-push": {
"ANDROID_SUPPORT_V13_VERSION": "27.+", // already there
"FCM_VERSION": "11.6.2", // already there
"SENDER_ID": "numeric key obtain from firebase console" // added
},
Open app.module.ts and import import { Push } from
'#ionic-native/push'; add Push under providers there ...
providers: [
StatusBar,
SplashScreen,
Push, ....
Then in a provider
i imported import { Push, PushObject, PushOptions } from '#ionic-native/push';
then in costructor i added private push: Push,
and in the class of that provider i wrote a function like below
pushSetup(){
// to check if we have permission
this.push.hasPermission()
.then((res: any) => {
if (res.isEnabled) {
console.log('We have permission to send push notifications');
} else {
console.log('We do not have permission to send push notifications');
}
});
// Create a channel (Android O and above). You'll need to provide the id, description and importance properties.
this.push.createChannel({
id: "testchannel1",
description: "My first test channel",
// The importance property goes from 1 = Lowest, 2 = Low, 3 = Normal, 4 = High and 5 = Highest.
importance: 3
}).then(() => console.log('Channel created'));
// Delete a channel (Android O and above)
this.push.deleteChannel('testchannel1').then(() => console.log('Channel deleted'));
// Return a list of currently configured channels
this.push.listChannels().then((channels) => console.log('List of channels', channels))
// to initialize push notifications
const options: PushOptions = {
android: {
senderID:"150482406038",
},
ios: {
alert: 'true',
badge: true,
sound: 'false'
},
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any) => console.log('Received a notification', notification));
pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', registration));
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
}
Now imported that provider where I want to use that , and called
that function from there . but call it only after
this.platform.ready().then(() => { or when a successful login.
I have shared this because i found it little difficult and got confusing guides over web
Please comment if you found it wrong or not working in your case.
I have been using this tutorial: https://medium.com/#felipepucinelli/how-to-add-push-notifications-in-your-cordova-application-using-firebase-69fac067e821 and Android push notifications worked out of the box. Good luck!
^ you might wanna try the cordova-plugin-firebase plugin as Chrillewoodz has mentioned

Resources