I was able to fix it, although is a very ugly way and I wanted to ask you if there is a better way to
of ding this
so, in order to make this work, I had to add my pages in the xaml
Shell
x:Class="DemyAI.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:badge="clr-namespace:Syncfusion.Maui.Core;assembly=Syncfusion.Maui.Core"
xmlns:helpers="clr-namespace:DemyAI.Helpers"
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:pages="clr-namespace:DemyAI.Views"
xmlns:sfavatar="clr-namespace:Syncfusion.Maui.Core;assembly=Syncfusion.Maui.Core"
xmlns:vm="clr-namespace:DemyAI.ViewModels"
Title="DemyAI"
x:DataType="vm:AppShellViewModel"
Shell.NavBarIsVisible="False"
Shell.TabBarIsVisible="False">
<ShellContent
ContentTemplate="{DataTemplate pages:StartupPage}"
Route="StartupPage"
Shell.FlyoutBehavior="Disabled"
Shell.FlyoutItemIsVisible="False" />
<ShellContent
ContentTemplate="{DataTemplate pages:LoginPage}"
Route="LoginPage"
Shell.FlyoutBehavior="Disabled"
Shell.FlyoutItemIsVisible="False" />
<ShellContent
ContentTemplate="{DataTemplate pages:NoInternetPage}"
Route="NoInternetPage"
Shell.FlyoutBehavior="Disabled"
Shell.FlyoutItemIsVisible="False" />
<ShellContent
ContentTemplate="{DataTemplate pages:RoleSelectionPage}"
Route="RoleSelectionPage"
Shell.FlyoutBehavior="Disabled"
Shell.FlyoutItemIsVisible="False" />
<Shell.FlyoutFooterTemplate>
<DataTemplate>
<Button
Margin="20"
Command="{Binding SignOutCommand}"
CornerRadius="8"
Text="Log out" />
</DataTemplate>
</Shell.FlyoutFooterTemplate>
</Shell>
If I don't put, I get null exception the first time I run the app
Then I tweak my method
public static List<ShellContent> GeetDefaultMenuItems() {
return
[
new() { ContentTemplate = new DataTemplate(typeof(StartupPage)),
Route = nameof(StartupPage), FlyoutItemIsVisible = false },
new() { ContentTemplate = new DataTemplate(typeof(LoginPage)),
Route = nameof(LoginPage), FlyoutItemIsVisible = false },
new() { ContentTemplate = new DataTemplate(typeof(NoInternetPage)),
Route = nameof(NoInternetPage), FlyoutItemIsVisible = false },
new() { ContentTemplate = new DataTemplate(typeof(RoleSelectionPage)),
Route = nameof(RoleSelectionPage), FlyoutItemIsVisible = false }
];
}
}
and then when I log out, I cleared.
async Task SignOut() {
SecureStorage.Default.RemoveAll();
var defaultItems = FlyoutHelper.GeetDefaultMenuItems();
Shell.Current.Items.Clear();
foreach(var item in defaultItems) {
Shell.Current.Items.Add(item);
}
await appService.NavigateTo($"//{nameof(LoginPage)}", true);
if yo see closely, the code from the Appshell.xaml, and my
GeetDefaultMenuItems
are the same. thing