Flutter and Socket.io: No reaction from code, no errors, unable to debug - flutter

I'm creating an app which should trigger a longer process in my nodejs server whereas the app should receive progress updates via socket.io.
The node server with socket.io works fine, I already tested it with a web client in the browser. However, I can't get the flutter code of the socket_io_client 1.0.2 package to execute in my flutter app.
This code is inside a method which is called once a user presses a button:
try {
print("step 1");
IO.Socket socket = IO.io('http://localhost:3000',
OptionBuilder().setTransports(['websocket']).build());
socket.on('connect', (_) {
print('connect: ${socket.id}');
socket.emit('process1', json.encode(_req));
});
socket.on('progress', (data) => print(data));
socket.onDisconnect((_) {
print('disconnect');
_finished = true;
});
} catch (e) {
print(e);
print("error");
}
print("step 2");
When clicking the button, the method executes, but not the socket part. In the console, I immediately get
step 1
step 2
but nothing else happens: The console logs the test statements immediately and the server never notices any incoming connections ... it is as the socket.io related code is just never executed. No errors, no console messages, nothing!
Does anyone have an idea why the codes behaves like this, why nothing happens?
Flutter (Channel stable, 2.10.4)
socket_io_client: ^1.0.2

I had the same problem with same versions of flutter and socket_io_client.
After changing the sockit_io_client to version ^2.0.0-beta.4-nullsafety.0 it was working.
https://pub.dev/packages/socket_io_client/versions/2.0.0-beta.4-nullsafety.0
There are many discussions about it on their github page. Will be fixed in the next releases.

Related

Flutter web: How to hide alert message in the console when the HTTP status codes is failed?

I am using the API in Flutter.
Sometimes the server will return failed HTTP status codes and Flutter always auto-generated the alert message with shown the API URL in the console. I don't want to shown the API URL and this alert message makes the app look not complete from the user's perspective. I want to hide these alert messages. How to do that?
Example:
You can use the try/catch block.
try {
await http.get('...')
...
} catch(e) {
print(e);
}
'This is normal behavior for the browser' By https://github.com/flutter/flutter/issues/112155#issuecomment-1255310351
This is a way that can clear the console -> https://stackoverflow.com/a/73862039/17798537

Flutter: converting project to web

I have a flutter project currently working well on Android and Ios. I am currently trying to get it working on the web, and while the frontend seems to be fine, im noticing issues with my streams. For instance, when initially loading the app as an authenticated user, a stream of special users called Stingrays is loaded. This works fine on mobile, however in web i get hung up on the following:
error:
Failed to evaluate expression 'stingrays': InternalError: No frame with index 84.
bloc code:
void _onLoadStingray(
LoadStingray event,
Emitter<StingrayState> emit,
) {
_firestoreRepository.stingrays.listen((stingrays) {
add(
UpdateStingray(stingrays: stingrays),
);
});
}
Stream:
Stream<List<Stingray?>> get stingrays {
return FirebaseFirestore.instance
.collection('stingrays')
.snapshots()
.map<List<Stingray?>>(_stingrayListFromSnapshot);
}
Its also not loading any image in the app, saying:
ImageCodecException: Failed to load network image.
Any idea whats going on with all this?

Flutter firebase messaging v9.0.0 - Not firing events

I have an app that was using firebase messaging 7.0.3 and all worked perfectly. But when I migrated to firebase messaging 9.0.0, the push notifications are not being handled.
I know that the app is correctly linked to firebase and cloud messaging because in background I see the push notification comming, the problem is when I click that notification the app don't handle this event. Also, when the app is in foreground, the event of receiving the notification is not being triggered.
Specifically, the functions FirebaseMessaging.onMessage and FirebaseMessaging.onMessageOpenedApp are not working. My code is:
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print("notification: message");
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print("notification: resume");
});
The prints are never called, and if I put some more code inside isn't executed too.
I also call FirebaseMessaging.getToken and I can get the token, plus when the app is in background I get the push notification, so is not a link problem with firebase. In the logs, when I receive the push I can see a message saying: Broadcast received for message. So I assumed that the push is arriving in all the occasions, and I am doing something wrong in the code.
I tested all cases in Android and iOS physical devices.
Someone know why this occurs?
I came across this exact same issue after migrating and upgrading to 9.0.0.
There is a minor issue with 9.0.0 plugin.
The fix can be found here:
https://github.com/FirebaseExtended/flutterfire/issues/4949
To cut a long story short, if you navigate to the definition of the factory
RemoteMessage.fromMap() Using Cmd+Click or Ctrl+Click while hovering over the RemoteMessage class with the mouse), in the return statement, change contentAvailable: map['contentAvailable'], to contentAvailable: map['contentAvailable']??false.
Notifications are now working for me again now.
This should work for you until the plugin is fixed.

Ionic Capacitor Browser closes automatically

I am trying to implement an OAuth2 implicit grant frow with a redirect.
Using the browser like this:
import { Plugins } from '#capacitor/core';
const { Browser } = Plugins;
await Browser.open({ url: loginUrl });
results in navigating to the login page, but then immediately jumping back to the previous (main app) screen. Any idea why? BTW, Angular's Platform.paused observable is getting triggered when opening the url and when jumping back (not-paused) as well
In case someone else stumbles upon this issue:
the problem was only on an Android Emulator, not on a real device. Wiping data in the AVD manager made it work in the Emulator as well.

WL.Client.Logout not calling its onSuccess or onFailure callbacks?

Using Mobilefirst Platform 7.1,
I have noticed that logout function has stopped working. I have a browser web app which has a logout button which triggers:
WL.Client.logout("MyAuthenticatorRealm", {
onSuccess: function(res) {
console.log("success server logout"); // Never called :(
WLAuthorizationManager.obtainAuthorizationHeader().then (
function(header) {
// I would reload the app here,
},
function(error) {
...
});
},
onFailure: function(res) {
console.log("failure server logout"); // Never called :(
}
});
But callbacks are never called.
I have checked the sample code from this tutorial and I can see the same thing happening too.
Is there something specific I need to add in 7.1? This used to work in 7.0
EDIT 2015/08/31
There is nothing in the server logs. The client web app seem to be doing a request to authorization/v1/authorization?client_id=XYZ&scope=-MyAuthenticatorRealm&isAjaxRequest=true&x=0.07530371774919331 which returns 200 success.
EDIT 2013/09/17
With the new version (7.1.0.00.20150913-2345) the callback is called! However now I get an exception:
Uncaught ReferenceError: WLAuthorizationManager is not defined
Is this the correct way to do the logout for the latest version? I am trying the "Desktop Browser"
There is a known issue currently in MobileFirst Platform 7.1
APAR PI47591 WL.CLIENT.LOGOUT DOES NOT WORK IN HYBRID PREVIEW
You can open a PMR with IBM to share your interest for this fix, and get updated.