How to pop an alert dialog on Flutter from outside the builder - dart

Consider my scenario
//Show the progress indicator inside an alert to block the user
showAlertProgressIndicator();
// Get the data
await DataManager.get().getDummyData().then((value){
// After data acquisition pop the alertProgressIndicator
});
How can I achieve this?

I think it should be simple
Navigator.pop(context); or
void closeAlert() {
Navigator.pop(context);//it will close last route in your navigator
}
I guess these 2 methods in the same build(). So they have the same BuildContext, so above should work.

I have created a sample app related to this situation. It is here https://github.com/Yahhi/flutter_dialog_test
Context is the same and dialog disappears after 5 seconds on timer event.
Navigator.of(context).pop();

Related

iOS: Dismiss presented ViewController which is an instance of specific Class

I am using NYAlertViewController to display dialogs in my iOS-App. It can happen that I just opened a dialog when a background process tries to trigger another dialog. If this happens, the second dialog is not shown. I would like to close all other dialogs before opening a new one. How could I do this?
The Dialogs are shown with presentViewControllerAnimatedCompletion.
Maybe I can dismiss all ViewControllers that are instances of NYAlertViewController?
Any thoughts on that? Thanks!

Blackberry How to Block the Screen From Tapping When Status.Show Invoked?

I want to block my screen for listening a tap or click when the show.status("Please Wait",2 AnyTimeLimit); is invoked.
Actually I'm sending a hit to a web service and meanwhile I'm displaying a message "Please Wait" with 2 seconds wait. But after those 2 seconds It starts listening the tap/click. How can I block them to listen tapEvent/ClickEvent when displaying message?
Thanks,
You will have to make a custom screen that overrides PopupScreen for that. In your implementation, you will have to override onUiEngineAttached, like so -
protected void onUiEngineAttached(boolean attached)
{
super.onUiEngineAttached(attached);
if(attached)
{
// start server hit thread, which closes the screen when done
}
}
After that, just push the screen using UiApplication.getUiApplication.pushModalScreen(). You will want to keep the data you received in a byte array somewhere in the screen's instance which you can retrieve by calling a getter once the screen has been popped.

push modalscreen called my noneventherad

I know this is very basic, but I am not able to figure out why I am getting this.
I am running a splash screen, and in the splash screen I am running a background thread for performing my required operation to contact server.
After the background thread finishes its task, the listener in the splash screen creates an object for the next screen and sends it to the method below:
public void swapScreen(final TopNewsScreen _tn)
{
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run()
{
UiApplication.getUiApplication().popScreen();
UiApplication.getUiApplication().pushScreen(_tn);
}
});
}
Help of any sort is welcome.
The code you posted looks fine. I've seen "push modalscreen called from noneventhread" happen when there is a Dialog.inform or Dialog.ask call somewhere on a background thread.
Double check your background thread, and make sure it doesn't try to throw up some UI.
popScreen() takes a screen as an argument, so there should be one there.
When the last (or only) screen your application has pushed to the display is removed, the application exits. I would suggest pushing _tn first, then poping the splash screen.
The better way to handle this situation is:
class SplashScreen extends FullScreen
{
protected void onObscured()
{
close();
}
}
And simply push your screen (TopNewScreen) like you are doing. When the SplashScreen is not shown anymore, the screen closes by itself.

What is the best way to create a loading screen class for a Monotouch App?

I need to load and process many things before my app starts, so when I test it on my iPhone it's always killed by iOS because it hangs the iPhone for too much time.
I then decided to write a loading screen class for my Apps, something that shows immediatly a logo and a progress indicator (keeping it responsive to avoid being killed by iOS), while in a background a separate thread initializes all my ViewControllers and then closes the loading screen and shows the main window.
What is the best way to do it with MonoTouch?
Any suggestion is welcome.
Thank you.
This is how I do it:
In the FinishedLaunching method, initialize and add your splash view to the main window:
window.AddSubview(this.splashView);
After that, invoke your code that does all the stuff you want to do in a thread/async invocation. I usually use the ThreadPool. Remember to invoke on the main thread:
ThreadPool.QueueUserWorkItem(delegate {
this.BeginInvokeOnMainThread(delegate {
//Initialize stuff here
//...
//when done, add your initial view to the window and remove the splash view
//eg.:
//window.AddSubview(myController.View);
//this.splashView.RemoveFromSuperview();
});
});
// show the window, which only displays the splash view now and return
window.MakeKeyAndVisible();
return true;
A rough example, but I hope it helps.

MainScreen not pop after calling popScreen()

I try to pop the main screen using
UiApplication.getUiApplication().popScreen(getScreen());
But after executing this line main screen not poped and my application hanged.
And I received the following message from console.
FocusHistory: Focus lost; App AppName; Component net.rim.device.api.ui.component.ButtonField
try to use
UiApplication.getUiApplication.popScreen((UiApplication.getUiApplication().getA‌​ctiveScreen())
UiApplication.getUiApplication().popScreen(this);
Or
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());

Resources