Login flow with Intrnet check

Eduardo Gomez 3,426 Reputation points
2024-03-05T12:00:23.7133333+00:00

I have my shell

 <ShellContent
        ContentTemplate="{DataTemplate pages:StartupPage}"
        Shell.FlyoutBehavior="Disabled"
        Route="StartupPage"
        Shell.FlyoutItemIsVisible="False" />
    <ShellContent
        ContentTemplate="{DataTemplate pages:LoginPage}"
        Shell.FlyoutBehavior="Disabled"
        Route="LoginPage"
        Shell.FlyoutItemIsVisible="False" />
    <ShellContent
        ContentTemplate="{DataTemplate pages:NoInternetPage}"
        Shell.FlyoutBehavior="Disabled"
        Route="NoInternetPage"
        Shell.FlyoutItemIsVisible="False" />
    <FlyoutItem
        FlyoutDisplayOptions="AsMultipleItems"
        Route="WelcomePage">
        <ShellContent
            Title="Welcome"
            ContentTemplate="{DataTemplate pages:WelcomePage}" />
        <ShellContent
            Title="Join meeting"
            ContentTemplate="{DataTemplate pages:JoinMeetingPage}" />
        <ShellContent
            Title="Manage Course"
            ContentTemplate="{DataTemplate pages:ManageCoursePage}" />
        <ShellContent
            Title="New Lecture"
            ContentTemplate="{DataTemplate pages:NewLecturePage}" />
        <ShellContent
            Title="New Test"
            ContentTemplate="{DataTemplate pages:NewTestPage}" />
        <ShellContent
            Title="Schedule lecture"
            ContentTemplate="{DataTemplate pages:ScheduleLecturePage}" />
        <ShellContent
            Title="Schedule test"
            ContentTemplate="{DataTemplate pages:ScheduleTestPage}" />
        <ShellContent
            Title="Assigned courses"
            ContentTemplate="{DataTemplate pages:NotificationsPage}" />
    </FlyoutItem>
</Shell>

the first page, is the startupPage

    private readonly StartupPageViewModel startupPageViewModel;
    public StartupPage(StartupPageViewModel startupPageViewModel) {
        InitializeComponent();
        this.startupPageViewModel = startupPageViewModel;
        BindingContext = startupPageViewModel;
    }
    protected override async void OnAppearing() {
        base.OnAppearing();
        await startupPageViewModel.CheckInternet();
    }
}

I also have the vm

public class StartupPageViewModel(IAppService appService, IConnectivity connectivity) : BaseViewModel {
    public async Task CheckInternet() {
        if(connectivity.NetworkAccess is not NetworkAccess.Internet) {
            await appService.NavigateTo($"//{nameof(NoInternetPage)}");
        } else {
            await appService.NavigateTo($"//{nameof(LoginPage)}");
        }
    }
}

and the app

    public App(AppShell shell) {
        InitializeComponent();
        Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(Constants.LICENSE);
        MainPage = shell;
    }
}

but I get the error

Pending Navigations still processing

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,404 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 41,926 Reputation points Microsoft Vendor
    2024-03-06T05:57:09.89+00:00

    Hello,

    Pending Navigations still processing

    This is a known issue with shell navigation, and based on the discussion in Pending Navigations still processing exception when navigating to the page #17608, there are multiple ways you can work around it.

    Workaround 1:

    If I add await Task.Delay(1) it will work.

    Workaround 2:

    I had the same issue only on windows, I felt the Task.Delay(1) workaround a bit cheap and dirty so came up with this code:

    if (DeviceInfo.Platform == DevicePlatform.WinUI)
    {
        AppShell.Current.Dispatcher.Dispatch(async () =>
        {
            await Shell.Current.GoToAsync($"//{nameof(DashboardPage)}");
        });
    }
    else
    {
        await Shell.Current.GoToAsync($"//{nameof(DashboardPage)}");
    }
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.