Popping a route from the route itself #32
-
Hi! What I'd need is a way to call I am not sure how to solve this issue: I've tried hacking something in the BuildPage method, but it feels dirty as it's an awkward attempt at shoehorning side effects in the build method. I settled on the following internal class CameraPage : PageRoute
{
private readonly PhotoCaptureService photoCaptureService;
public CameraPage(PhotoCaptureService photoCaptureService)
: base(new RouteSettings("TakePicture", RouteModalType.Fullscreen))
{
this.photoCaptureService = photoCaptureService;
}
protected override async Task OnFocus()
{
try
{
var ph = await this.photoCaptureService.TakePicture(); // the async operation
this.SetResult(ph);
}
catch (OperationCanceledException)
{
this.SetResult(false);
}
finally
{
await this.ApplyScreenEvent(ScreenEvent.Unfocus);
await this.ApplyScreenEvent(ScreenEvent.Destroy);
}
}
protected override sealed Widget BuildTransitions(
BuildContext context,
AnimationController animation,
AnimationController secondaryAnimation,
Widget child
)
{
return new CompositeTransition
{
Opacity = secondaryAnimation.Drive(new FloatTween(0, 1)),
Child = new CompositeTransition
{
Opacity = animation.Drive(new FloatTween(0, 1)),
Child = new Empty(),
}
};
}
} This seems to work, in the sense that the fading animation of the CameraPage route is actually executed, but the route never gets popped off the stack. Thanks in advance for any help 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can send a command to close the route immediately after opening it: Navigator.Push(context, ...);
Navigator.Pop(context); An alternative solution is to move the asynchronous logic into a widget: public override async void InitState()
{
await this.photoCaptureService.TakePicture();
Navigator.Pop(Context);
} |
Beta Was this translation helpful? Give feedback.
You can send a command to close the route immediately after opening it:
An alternative solution is to move the asynchronous logic into a widget: