Flutter - Connectycube_flutter_callkit not working in the background or terminated - flutter

i'm using connectycube for receiving calls but when i accept call while is in the background like the image below
it navigates me the home page but not the call here is the code
void videocaller( var friendName){
Uuid uuid = Uuid();
CallEvent callEvent = CallEvent(sessionId: uuid.v4() + "1", callType: 1, callerId: 0,
callerName: friendName, opponentsIds:{1234});
Future<void> _onCallAccepted(CallEvent callEvent) async {
_joinMeetingVideo(friendName);
}
Future<void> _onCallRejected(CallEvent callEvent) async {
}
Future onCallRejectedWhenTerminated(CallEvent? callEvent) async {
}
Future onCallAcceptedWhenTerminated(CallEvent? callEvent) async {
_joinMeetingVideo(friendName);
}
ConnectycubeFlutterCallKit.onCallRejectedWhenTerminated = onCallRejectedWhenTerminated;
ConnectycubeFlutterCallKit.onCallAcceptedWhenTerminated = onCallAcceptedWhenTerminated;
ConnectycubeFlutterCallKit.instance.init(
onCallAccepted: _onCallAccepted,
onCallRejected: _onCallRejected,
);
ConnectycubeFlutterCallKit.showCallNotification(callEvent);
ConnectycubeFlutterCallKit.setOnLockScreenVisibility(isVisible: true);
}
i tried it with getx to navigate to jitsi call but it does not work
actually the problem is that jitsi function [_joinMeetingVideo(friendName);] is not a page where i can navigate to it's a function so it can't be executed enless the app is open this why it opens the home page of the app but not the video call itself but unfortunately i could't find a solution for this issue. any ideas ??

Related

Error: No named parameter with the name 'onSelectNotification'

class HelperNotification {
static Future<void> initialize(FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin) async {
var androidInitialize = new AndroidInitializationSettings('notification_icon');
var iOSInitialize = new DarwinInitializationSettings();
var initializationsSettings = new InitializationSettings(android: androidInitialize, iOS: iOSInitialize);
flutterLocalNotificationsPlugin.initialize(initializationsSettings, onSelectNotification:(String? payload) async {
try{
if(payload != null && payload.isNotEmpty) {
// Get.toNamed(RouteHelper.getOrderDetailsRoute(int.parse(payload)));
}else {
// Get.toNamed(RouteHelper.getNotificationRoute());
}
}catch (e) {}
return;
});
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
I Found that there was an update with the local notification package but i was trying to impliment it and was unsuccessful can you help me figure it out?
Since version 10.0.0 of the flutter_local_notifications plugin, they removed onSelectNotification parameter. You can read more about it in their changelog:
Breaking change
callbacks have now been reworked. There are now the
following callbacks and both will pass an instance of the
NotificationResponse class onDidReceiveNotificationResponse: invoked
only when the app is running. This works for when a user has selected
a notification or notification action. This replaces the
onSelectNotification callback that existed before. For notification
actions, the action needs to be configured to indicate the the app or
user interface should be shown on invoking the action for this
callback to be invoked i.e. by specifying the
DarwinNotificationActionOption.foreground option on iOS and the
showsUserInterface property on Android. On macOS and Linux, as there's
no support for background isolates it will always invoke this callback
onDidReceiveBackgroundNotificationResponse: invoked on a background
isolate for when a user has selected a notification action. This
replaces the onSelectNotificationAction callback
Read more here: https://pub.dev/packages/flutter_local_notifications/changelog

Future Builder doesn't update view always

I have a future builder, and Im using two future variables:
Future<List<Notifications>>? notificationsOfTheDay; //get saved notifications from db
Future<List<NotificationCategory>>? notificationsByCat; // sort/modify "notificationsOfTheDay"
I'm sending notificationsByCat to Future Builder.
The issues:
While the app starts, the future builder is able to receive all the notifications and manipulate the data with some asynchronous operations.
But sometimes the Future Builder displays blank.
I'm also appending received notifications to the existing Future Variable notificationsOfTheDay, when sometimes the view does not update.
Code snippets are listed below:
Here is my initState
void initState() {
super.initState();
initPlatformState(); // Notification Listener Service
notificationsOfTheDay = initializeData(isToday);
}
initilizeData Method
Future<List<Notifications>> initializeData(bool istoday) async {
notificationsOfTheDay = initializeNotifications(istoday);
if (notifications!.length > 0) {
notificationsByCat = notificationsByCategory(notificationsOfTheDay); //sorting/manipulation of existing future
}
return notifications!;
}
notificationsByCategory
Future<List<NotificationCategory>> notificationsByCategory(
List<Notifications> notificationsFuture) async {
return await NotificationsHelper.getCategoryListFuture(
isToday ? 0 : 1, notificationsFuture);
}
When any new notifications are received, it is inserted into the db and the exising future is appended with the new notification;
setState(() {
notificationsOfTheDay =
appendElements(notificationsOfTheDay!, _currentNotification!);
notificationsByCat = notificationsByCategory(notifications!);
});
Future<List<Notifications>> appendElements(
Future<List<Notifications>> listFuture,
Notifications elementToAdd) async {
final list = await listFuture;
list.add(elementToAdd);
return list;
}
Can anyone please guide me to a solution? Tried many combinations. If I'm directly showing the data without modifying it according to category, it works fine.
Where am I going wrong?

How to handle reading from database when API-request hasn't finished yet to save to database in Flutter?

For my App i'm loading the link for the background-image for each screen from my API.
Right after the query that downloads and saves the image-link, i'm querying the link from the database.
The problem now is, that the function isn't waiting for the download and saving to finish although i'm using await, therefor i get an empty result from the database and get an error from the imageloader.
Future<String> downloadAsset(String name) async {
final Map<String, String> _json = {
'mandant': Config.mandant,
'name': name
};
final query = MakePost('get_app_assets', false, _json, saveAsset);
await query.queryAPI(); // Function won't wait for this to finish
String ret = await dbAppAssets.getText(name); // Get link from database
return ret;
}
I've already tried to use .then(), but the same thing happens.
This only happens initially on the first call of each screen, but how is this normally beeing handled?
I'm using riverpod with futureProviders if that matters.
I do not know where you are using the downloadAsset function, but when you use Future on a function you should also await the function where you are using it, for example:
Future<void> _reverseScrollToTopAnimation() async {
await controller!.reverse();
_showBackToTopButton = false; // hide the back-to-top button
}
then, wherever you call it you should also await that function:
await _reverseScrollToTopAnimation();
If not the function will act as a synchronous operation even though you are using await inside the function.

Open an app in flutter based on the url provided in the email sent for verification

So I have been working on a flutter app and once the user registers through my app they are sent an email for the verification of their account. Once the url in the link is tapped they are verified. Now after their verification,the users must be redirected to the app. I looked into firebase dynamic links but in all of the articles,they were trying to share their app by generating a link. Is there a way I can implement this? Thanks in advance!
Use this package
https://pub.dev/packages/uni_links
For getting the link when the app is started.
This is the case in which your app was in the closed state.
Future<Null> initUniLinks() async {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
String initialLink = await getInitialLink();
// Parse the link and warn the user, if it is not correct,
// but keep in mind it could be `null`.
} on PlatformException {
// Handle exception by warning the user their action did not succeed
// return?
}
}
For listening to link clicks. This is for the case when your app is already open and you click the link.
_sub = getLinksStream().listen((String link) {
// Parse the link and warn the user, if it is not correct
}, onError: (err) {
// Handle exception by warning the user their action did not succeed
});
// NOTE: Don't forget to call _sub.cancel() in dispose()
}
Usually, you need to implement both of them together since your app may be in the closed state or open state while you click the link.
Future<Null> initUniLinks() async {
try {
String initialLink = await getInitialLink();
} on PlatformException {
}
_sub = getLinksStream().listen((String link) {}, onError: (err) {});
}}

Flutter: How to check if app is running on background from firebase messaging plugins onBackgroundMessage

I'm using firebase_messaging plugin to register a callback handler with onBackgroundMessage for my data-only payload of firebase messaging.
If the app is in foreground or in background, the normal way of operation is using sockets to get the data from network and show notification from the app.
But when the app is in killed state, I would like to show the notification by fetching the data from network.
But these operations conflicts when the app is in background as onBackgroundMessage is getting called in background also.
If I'm not wrong, the handler is running on a separate isolate and it has no access to the main contents.
So how can I differentiate the killed and background state of the app from this isolated function?
You can use IsolateNameServer to register a ReceiverPort from the foreground when it is running and remove it when the foreground is not running. Then on the background isolate check if it exists and if so redirect the FCM message through the port to the foreground for handling on foreground.
Something along the lines of this:
const FOREGROUND_ISOLATE_PORT_NAME = 'foreground_port';
class NotificationManager {
ReceivePort? _foregroundReceivePort;
StreamSubscription<RemoteMessage>? _fcmMessageSubscription;
init() async {
FirebaseMessaging.onBackgroundMessage(_fcmMessageHandlerBackground);
_fcmMessageSubscription = FirebaseMessaging.onMessage.listen(_fcmMessageHandlerForeground);
_foregroundReceivePort = ReceivePort();
IsolateNameServer.registerPortWithName(
_foregroundReceivePort!.sendPort,
FOREGROUND_ISOLATE_PORT_NAME,
);
_foregroundReceivePort!.listen((message) {
if (message is RemoteMessage) {
log('got fcm message for handling in foreground');
_fcmMessageHandlerForeground(message);
}
});
}
shutdown() async {
_fcmMessageSubscription?.cancel();
IsolateNameServer.removePortNameMapping(FOREGROUND_ISOLATE_PORT_NAME);
_foregroundReceivePort!.close();
_foregroundReceivePort = null;
}
}
With these two top level functions:
Future<void> _fcmMessageHandlerForeground(RemoteMessage message) async {
// ... handle message in foreground ...
}
Future<void> _fcmMessageHandlerBackground(RemoteMessage message) async {
final foreground = IsolateNameServer.lookupPortByName(FOREGROUND_ISOLATE_PORT_NAME);
if (foreground != null) {
log("redirecting FCM message to foreground");
foreground.send(message);
} else {
// ... handle message in background ...
}
}