C
C#3mo ago
eduardoA

Login Flow with shell

the fir time I login, everything is fine, but if I do it again I get this
An item with the same key has already been added. Key: 0'
An item with the same key has already been added. Key: 0'
This also happens if I navigate to the same page twice within the app shell
public partial class LoginPageViewModel

[ObservableProperty]
bool isPopOpen;

[ObservableProperty]
User user = new();

[RelayCommand]
void OpenPopUp() {
IsPopOpen = true;
}

[RelayCommand]
async Task Login() {

IsBusy = true;

//var user = await authenticationService.LoginWithEmailAndPassword(User.Email!, User.Password!);
//var user = await authenticationService.LoginWithEmailAndPassword("admin@admin.com", "123456");

await appService.NavigateTo($"{nameof(NewLecturePage)}");
public partial class LoginPageViewModel

[ObservableProperty]
bool isPopOpen;

[ObservableProperty]
User user = new();

[RelayCommand]
void OpenPopUp() {
IsPopOpen = true;
}

[RelayCommand]
async Task Login() {

IsBusy = true;

//var user = await authenticationService.LoginWithEmailAndPassword(User.Email!, User.Password!);
//var user = await authenticationService.LoginWithEmailAndPassword("admin@admin.com", "123456");

await appService.NavigateTo($"{nameof(NewLecturePage)}");
<ShellContent
ContentTemplate="{DataTemplate pages:LoginPage}"
Route="loginPage"
Shell.FlyoutBehavior="Disabled"
Shell.FlyoutItemIsVisible="False" />

<FlyoutItem>
<ShellContent
ContentTemplate="{DataTemplate pages:NewLecturePage}"
Route="NewLecturePage" />
</FlyoutItem>
<ShellContent
ContentTemplate="{DataTemplate pages:LoginPage}"
Route="loginPage"
Shell.FlyoutBehavior="Disabled"
Shell.FlyoutItemIsVisible="False" />

<FlyoutItem>
<ShellContent
ContentTemplate="{DataTemplate pages:NewLecturePage}"
Route="NewLecturePage" />
</FlyoutItem>
public class StartupPageViewModel : BaseViewModel {

private readonly IAppService _appService;
private readonly IConnectivity _connectivity;

public StartupPageViewModel(IAppService appService, IConnectivity connectivity) {

_appService = appService;
_connectivity = connectivity;

CheckInternet(_connectivity.NetworkAccess);

}

private void CheckInternet(NetworkAccess networkAccess) {
if(networkAccess is not NetworkAccess.Internet) {
_appService.NavigateTo($"{nameof(NoInternetPage)}");
} else {
_appService.NavigateTo($"{nameof(LoginPage)}");
}
}
}
public class StartupPageViewModel : BaseViewModel {

private readonly IAppService _appService;
private readonly IConnectivity _connectivity;

public StartupPageViewModel(IAppService appService, IConnectivity connectivity) {

_appService = appService;
_connectivity = connectivity;

CheckInternet(_connectivity.NetworkAccess);

}

private void CheckInternet(NetworkAccess networkAccess) {
if(networkAccess is not NetworkAccess.Internet) {
_appService.NavigateTo($"{nameof(NoInternetPage)}");
} else {
_appService.NavigateTo($"{nameof(LoginPage)}");
}
}
}
0 Replies
No replies yetBe the first to reply to this messageJoin