How do I show / reset cancelled local notification in Flutter? - flutter

I am using flutter_local_notifications 12.0.2 I have a code which will show a notification and after I wanted to cancel it
But I have an if statement which I would like to trigger the notification back or uncancel it, is there any way I can achieve that?
P.S: I tried initializing it and calling .pendingNotificationRequests() but its not working
here is my code:
if (Geolocator.distanceBetween(newLoc.latitude!, newLoc.longitude!,
des.latitude, des.longitude) <
200) {
isNear = true;
NotificationApi.showBigTextNotification(
title: "IMPORTANT",
body: "Dont forget to visit our shop!",
fln: flutterLocalNotificationsPlugin);
flutterLocalNotificationsPlugin.cancel(0);
} else {
isNear = false;
NotificationApi.initialize(flutterLocalNotificationsPlugin);
flutterLocalNotificationsPlugin.pendingNotificationRequests();
}

Related

Flutter - Connectycube_flutter_callkit not working in the background or terminated

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 ??

Flutter save OneSignal notification message

I want to save the message from OneSignal push notification, so I can create a notification list.. but I have no idea to achieve this.. I open the Onesignal for flutter documentation but still no clue.. anyone can share some references to me?
In your main.dart make sure you have the listener setNotificationReceivedHandler activated. Then just save the notification.payload elements
OneSignal.shared.setNotificationReceivedHandler((notification) {
this.setState(() {
_debugLabelString =
"Received notification: \n${notification.jsonRepresentation().replaceAll("\\n", "\n")}";
newNotificationTitle = notification.payload.title;
newNotificationBody = notification.payload.body;
});
});

Show confirmation box in dhtmlx scheduler onbeforeviewchange

I want to show the confirmation box before view change. So when user change date for scheduler I want to show confirmation box whether user want to redirect to another date or not.
The simplest solution would be to use window.confirm
It pauses code execution until user choses any option, so you can use simple if-else statement:
scheduler.attachEvent("onBeforeViewChange", function (oldMode, oldDate, mode, date) {
if (oldMode && oldDate) {
if (oldMode !== mode || oldDate.valueOf() !== date.valueOf()) {
if (confirm("are you sure?")) {
return true;
}
return false;
}
}
return true;
});
demo: https://snippet.dhtmlx.com/140d2ff31
If you want a custom confirmation popup, which doesn't block the browser, you'll need to do a small workaround, since scheduler API doesn't support async event handlers:
1) when code enters onBeforeViewChange, you display the dialog and always return false from the handler in order to keep the same date
2) when the user confirms view change - you set some flag to temporary disable step 1 and call scheduler.setCurrentView from the callback. onBeforeViewChange runs again, you check the flag you've set and return true this time, allowing date change.
var callbackViewChange = false;
scheduler.attachEvent("onBeforeViewChange", function (oldMode, oldDate, mode, date) {
if (oldMode && oldDate) {
//
if (!callbackViewChange && (oldMode !== mode || oldDate.valueOf() !== date.valueOf())) {
dhtmlx.confirm({
text: "are you sure?",
callback: function (result) {
if (result) {
// set the flag in order to allow view change
callbackViewChange = true;
scheduler.setCurrentView(date, mode);
callbackViewChange = false;
}
}
});
// cancel view change while we wait for user action
return false;
}
}
return true;
});
demo: https://snippet.dhtmlx.com/a2b8b09b9

Possible to show users of your VSCode extension / color theme notifications on update?

Is it possible to show users of your extension or color theme notifications in Visual Studio Code? For someone who has my color theme or extension installed and is getting updates, I would like to possibly show this person a notification after they update the extension (That could be on launch of VSCode, or right after they go into the market to update & reload the extension and client themselves.)
For example: I think it would be beneficial to me and not invasive if they saw a notification after updating the extension saying "Feedback? Suggestions? Fixes?..on the theme?" OR notifying them of something changed in the theme that may not be favorable. So they can "opt out" of that change if they want (Like an extra set of borders around something or the color change of something.)
Obviously people with all notifications off would not be affected, but I thought an occasional notification after a rare update wouldn't be too bad. I have not been able to find info on if this is possible, and if it was, how to do it. Any info on this is appreciated. And if it is possible, those reading this, whether you've done it or not, would you recommend showing a notification to your theme users in that way?
Thanks :)
Show a notification on bottom-right corner, whenever your extension is updated. You can also control to show it only for major/minor releases.
That's how it looks:
Add below code to extension.ts:
import { window, ExtensionContext, extensions, env, Uri } from "vscode";
const extensionId = "jerrygoyal.shortcut-menu-bar";
// this method is called when your extension is activated
export function activate(context: ExtensionContext) {
showWhatsNew(context); // show notification in case of a major release i.e. 1.0.0 -> 2.0.0
}
// https://stackoverflow.com/a/66303259/3073272
function isMajorUpdate(previousVersion: string, currentVersion: string) {
// rain-check for malformed string
if (previousVersion.indexOf(".") === -1) {
return true;
}
//returns int array [1,1,1] i.e. [major,minor,patch]
var previousVerArr = previousVersion.split(".").map(Number);
var currentVerArr = currentVersion.split(".").map(Number);
if (currentVerArr[0] > previousVerArr[0]) {
return true;
} else {
return false;
}
}
async function showWhatsNew(context: ExtensionContext) {
const previousVersion = context.globalState.get<string>(extensionId);
const currentVersion = extensions.getExtension(extensionId)!.packageJSON
.version;
// store latest version
context.globalState.update(extensionId, currentVersion);
if (
previousVersion === undefined ||
isMajorUpdate(previousVersion, currentVersion)
) {
// show whats new notificatin:
const actions = [{ title: "See how" }];
const result = await window.showInformationMessage(
`Shortcut Menubar v${currentVersion} — Add your own buttons!`,
...actions
);
if (result !== null) {
if (result === actions[0]) {
await env.openExternal(
Uri.parse(
"https://github.com/GorvGoyl/Shortcut-Menu-Bar-VSCode-Extension#create-buttons-with-custom-commands"
)
);
}
}
}
}
You can see this implementation in my VSCode extension repo Shortcut Menu Bar
I think you can register the version during activation event and check for it on each activation. Then you can do whatever you want. For instance GitLens is migrating settings https://github.com/eamodio/vscode-gitlens/blob/master/src/extension.ts#L52 and i'm pretty sure I remember that they were opening a notification (but i have not found immediately in the code)
regards,

alert handling in ui automation iphone app unable to cancel the option

system.logElementTree();
var target = UIATarget.localTarget();
target.onAlert = function onAlert(alert) {
UIALogger.logDebug("There was an alert!");
target.onAlert.buttons()["No"].tap({x:164,y:278});
return false;
even though no option is clicked systen not performing any action
Can anyone please help me ...
Instead of BamboOS suggestion which loops through various positions, you can try this inside your onAlert function:
alert.tapWithOptions({tapOffset:{x:0.5, y:0.6}});
This tap targets the middle of the UIAAlert (x:0.5) and 60% from top to bottom (y:0.6). This works when there is only one button. You have multiple buttons, then you have to changed the value of x. This works for me.
I just published a blog post regarding UI Automation and dealing with alerts:
http://www.conduce.net/Blog.aspx?f=Automated-Test-of-iPad-Apps
Basically following alert handler worked for me:
UIATarget.onAlert = function onAlert(alert){
var name = alert.name();
UIALogger.logMessage("alert "+name+" encountered");
if(name == "errorAlert"){
var positionX = 500;
for(var positionY=300; positionY<600;positionY+=10){
target.tap({x:positionX,y:positionY});
}
return true;
}
return false;
}
I would either use the "cancelButton" or "defaultButton" methods when handling alerts.