I am using a popup page plugin. It works as below;
var confirm = new AlertDialog(new AlertSettings() { Title = "Confim Title", Message = "Confirm Question?"});
confirm.Callback += (result) =>
{
if (result)
{
//> do something
}
};
await PopupNavigation.PushAsync(confirm);
I am trying to write a service for getting callback result as bool as following;
public interface IDialogsService
{
Task<bool> DisplayConfirmAsync(string title, string message);
}
public class DialogsService : IDialogsService
{
public DialogsService()
{
}
public async Task<bool> DisplayConfirmAsync(string title, string message)
{
bool tresult = false;
var confirm = new AlertDialog(new AlertSettings() { Title = title, Message = message});
confirm.Callback += (result) =>
{
tresult = (bool)result;
};
await PopupNavigation.Instance.PushAsync(confirm);
return tresult;
}
}
I try to run Task for getting result as bool as below;
bool result = await DialogsService.DisplayConfirmAsync("Confim Title", "Confirm Question?");
My question is "above approach is correct or not?" Thank you in advance.