Circular progress button automatically trigger once the progress is complete - dart

I have a working circular progress button based ontapdown and ontapup, however i wanted it to trigger once the progress complete. Right now it only trigger only when the progress is complete and user tapUp.
onTapDown: (_) {
controller1.forward();
},
onTapUp: (_) {
if (controller1.status ==
AnimationStatus.forward) {
controller1.reverse();
} else if (controller1.status ==
AnimationStatus.completed) {
setState(() {
controller1.value = 0.0;
// widget.isClickCALLBOMBA = true;
// controller1.reverse();
Flushbar()
..title = allTranslations
.text('success')
..message =
"We will alert the bomba !"
..duration =
Duration(seconds: 3)
..backgroundColor =
Colors.red
..show(context);
});
}
},

You can add a listener to your AnimationController to do stuff when the animation is complete:
controller1.addStatusListener((status) {
if (status != AnimationStatus.completed) {
return;
}
//Animation is complete! Do completion stuff.
});

Related

Flutter Timer.Periodic stops during Sleep Mode, how can I re-enter into the logic loop using Lifecycle Code?

I'm still pretty new and I had a bug in my code wherein, if the device went to sleep during it's normal function, (while it was waiting for a response from a server) then the entire app basically just freezes, and doesn't come back.
Now I didn't have any lifecycle code in there at the time, so I understand that it's the solution, but how can I handle that specifically?
(Life cycle code)
#override
void initState() {
WidgetsBinding.instance.addObserver(this);
super.initState();
}
#override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
#override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
if(state == AppLifecycleState.paused) {
/*
What information Needs to be saved?
*/
} else if(state == AppLifecycleState.resumed) {
/*
What information needs to be restored, and how to do so if it's not
instantly obvious?
*/
}
}
(Code with Timer that is giving the issue)
//Timer to check Status of Trip, and take action based of Trip Status
Timer.periodic(timerInterval, (ztimer) { // Timer to constantly refresh information
counter++;
if ((counter >= 120) && (switchedScreens) && (splashActive)){
ztimer.cancel();
cancelReq();
Navigator.of(context).pop();
}
getInfo(sessionID); // Get Request Info
info = updateInfo(); // Refresh info in program.
if (info != null) {
reqStatus = info['status'];
if (dispatchVerified == true) { // Check to see if the call has been verified
if (reqStatus != previousReqStatus) { // Check to see if the Status of the call has changed
previousReqStatus = reqStatus;
if ((reqStatus == 'deleted') || (reqStatus == 'complete') || (reqStatus == 'noCall')) { // If the request status would end the call, do so
ztimer.cancel();
if (splashActive) { //if deleted by server, would still be on Splash Screen
splashActive = false;
Navigator.of(context).pop();
}
cancelReq();
} else if (reqStatus == 'accepted') { // If accepted, switch back from Splash Page
if (splashActive) {
splashActive = false;
Navigator.of(context).pop();
}
reqPosition = new LatLng(info['cab'][0]['latitude'], info['req'][0]['longitude']); // add and update the position of the request for the marker
if (!addedReqPosition) {
addedReqPosition = true;
addReqPosition();
}
} else if (reqStatus == 'canceled'){ // If Call was cancelled, but on Splash Page, ensure it's removed.
ztimer.cancel();
if (splashActive) {
splashActive = false;
Navigator.of(context).pop();
}
cancelReq();
} else if (reqStatus == 'editing') {
dispatchVerified = false;
splashActive = true;
stream = new DataStream();
Navigator.push(context, CupertinoPageRoute(builder: (context) => SplashPage(stream: stream)));
}
}
} else {
if (reqStatus == 'editing') {
} else if ((reqStatus == 'unassigned') || (reqStatus == 'pendingConfirmation')) { // Request has now been verified
if (switchedScreens) {
dispatchVerified = true;
switchedScreens = false;
stream.dataSink.add(true);
}
} else if (reqStatus == 'deleted'){ // If Call was Deleted by Server, reset state of app.
ztimer.cancel();
if (splashActive) {
splashActive = false;
Navigator.of(context).pop();
}
cancelReq();
}
}
}
if (booking == false) {
ztimer.cancel();
}
mapState.setState(() {});
});
What can I try next?

Having Multiple SetStates() in a Gesture Detector?

I can't get the set state to change in multiple areas from an onTap VoidCallback?
I have two AnimationController in different stateful widgets. What I would like to implement is that if controller1.value == 0.0 then it'll make sure that when onTap that the controller2.value == 1.0 and visa versa for if controller1.value == 1.0.
StatefulWidget bottom layer (passes the widget.onTapOpen/closed to the top layer)
onTap: () {
_toggleExpandingSheetPanelVisibility();
setState(() {
if (_controller1.value == 0.0){
widget.onTapOpen();
}
else if (_controller1.value == 1.0){
widget.onTapClosed();
}
});
},
StatefulWidget top layer
onTapOpen: _ensureVisible,
onTapClosed: _ensureInvisible,
void _ensureVisible() {
setState(() {
if (_controller2.value == 0.0) {
_toggleVisibility();
}
});
}
void _ensureInvisible() {
setState(() {
if (_controller2.value == 1.0) {
_toggleVisibility();
}
});
}
It worked when if (_controller2.value > or < 0.5) then it would toggle the visibility.

Javascript: Stop running interval in background

I am creating an extension for Firefox. This includes using self.port. Here's my code in panel.js:
self.port.on("showDlg", function(val) {
document.getElementById('queen').onclick = function(){
self.port.emit("song", 'queen');
};
document.getElementById('beatles').onclick = function(){
self.port.emit("song", 'beatles');
};
});
Here's the content.js:
self.port.on("song", function(val) {
if (val.code = 'queen'){
interval = setInterval(function () {
console.log('show must go on');
}, 1000);
} else if (val.code == 'beatles'){
interval = setInterval(function () {
console.log('yesterday');
}, 1000);
}
}
It is all working, when I click queen, it prints me show must go on every 1 second. But when I click beatles, it still prints show must go on along with yesterday.
How can I stop previous interval? As far as I understand, it runs in the background, and every action is a new instance. If so, how can I stop previous instance?
Thanks.
self.port.on("song", function(val) {
self.interval && clearInterval(self.interval);
self.interval = null;
if (val.code = 'queen'){
self.interval = setInterval(function () {
console.log('show must go on');
}, 1000);
} else if (val.code == 'beatles'){
self.interval = setInterval(function () {
console.log('yesterday');
}, 1000);
}
}

Updating a Button control with an NSTimer in Xamarin

I have created a very basic ios project that has a single button on it with it's title text property set to "Start". I am trying to have this button count down from 15.
I have added the event handler for the button as below.
void StartButton_TouchUpInside (object sender, EventArgs ea) {
_currentCount = 15;
_timer = NSTimer.CreateRepeatingScheduledTimer(TimeSpan.FromSeconds(1), () =>
{
if (_currentCount <= 0) {
StartButton.TitleLabel.Text = "Start";
_timer.Dispose();
} else {
string titleText = (_currentCount--).ToString ();
//Console.WriteLine(titleText);
StartButton.TitleLabel.Text = titleText;
//Console.WriteLine(StartButton.TitleLabel.Text);
//StartButton.SetNeedsDisplay();
}
});
}
So here is the strange thing. The Button changes to 15 just fine then it flashes back to "Start" then 14. Then 13 then "Start" then 12 etc... etc... etc...
Why is it doing this? And how do I prevent it from flashing back to start. Thanks in advance.
Try to use this.InvokeOnMainThread
private int counter = 0;
public override void WillActivate()
{
Console.WriteLine ("{0} will activate", this);
_timer = NSTimer.CreateRepeatingScheduledTimer(1, (timer) =>
{
this.InvokeOnMainThread(()=>{
Console.WriteLine("++++++++ NSTimer Call");
this.AlertTimeLabel.SetText(counter.ToString());
counter++;
});
});
}

Cordova: iOS: not calling pushPlugin.register, window.onNotificaiton.APN

The pushPlugin.register function is getting called for Android, but not iOS. Here is the code I have.
this.initialize is getting called and I see the first alert there -- alert('PushNotifications:initialize');
Any ideas? why pushPlugin.register and window.onNotificationAPN function don't seem to get called?. At one brief point it was working, IIRC. I'm not sure what changed.
Here's my config setup:
https://gist.github.com/adaptivedev/d33f38cd3d6cf10be9dc
Thanks!
.service('PushNotifications', function(Utility, $cordovaToast, $rootScope) {
alert('PushNotifications');
var pushPlugin = null;
/*
this.deviceRegId = function() {
$rootScope.getFDeviceId();
}
*/
this.initialize = function() {
alert('PushNotifications:initialize');
document.addEventListener('deviceready', function() {
//alert('PushNotifications:initialize:deviceready:device='+JSON.stringify(device));
pushPlugin = window.plugins.pushNotification;
if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
pushPlugin.register(
function(result) {
console.log('PushNotifications:initialize:1:result='+result);
},
function(result) {
alert('PushNotifications:initialize:2:result='+result);
console.log(JSON.stringify(result));
},
{
"senderID":"123",
"ecb":"onNotificationGCM"
});
} else {
pushPlugin.register(
function(result) {
alert('PushNotifications:initialize:1:result='+result);
//$rootScope.setDeviceId(result)
},
function(result) {
alert('PushNotifications:initialize:2:result='+result);
console.log(JSON.stringify(result));
},
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
});
}
});
// notifications for Android
window.onNotificationGCM = function(e) {
alert('onNotificationGCM:e='+JSON.stringify(e));
window.boosterNotification = e;
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
$rootScope.setDeviceId(e.regid);
}
break;
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if ( e.foreground )
{
// on Android soundname is outside the payload.
// On Amazon FireOS all custom attributes are contained within payload
var soundfile = e.soundname || e.payload.sound;
// if the notification contains a soundname, play it.
//var my_media = new Media("/android_asset/www/"+ soundfile);
//my_media.play();
}
else
{ // otherwise we were launched because the user touched a notification in the notification tray.
if ( e.coldstart )
{
//
}
else
{
//
}
}
var msg = e.payload.message.replace(/<b>/g, "")
msg = msg.replace(/<\/b>/g, "");
$cordovaToast.showShortCenter(msg).then(function(success) {
//$state.go('app.upcoming');
$rootScope.updateNotifications();
}, function (error) {
// error
}
);
//alert(e.payload.message);
//Only works for GCM
// e.payload.msgcnt + '</li>');
//Only works on Amazon Fire OS
// e.payload.timeStamp
break;
case 'error':
//e.msg
break;
default:
// Unknown
break;
}
};
// notifications for iOS
window.onNotificationAPN = function(result) {
alert('onNotificationAPN:result:1:='+JSON.stringify(result));
if ( event.alert )
{
//navigator.notification.alert(event.alert);
}
if ( event.sound )
{
//var snd = new Media(event.sound);
//snd.play();
}
if ( event.badge )
{
//.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
}
console.log('onNotificationAPN:result='+JSON.stringify(result));
window.boosterNotification = result;
};
};
});
I solved it! In Xcode, select the file (PushPlugin.m) and on right side check "Target Membership"

Resources