Hi @Eduardo Gomez ,
Thanks for your feedback. I have looked into it again and I think I have found the root cause.
The main issue was that camera detection wasn’t being re-enabled after the popup closed. In your original code, the Yes(), No(), and Closing() handlers didn’t consistently set ShouldDetect = true, and the Closing() handler was accidentally reopening the popup by setting PopUpDetectedOpen = true. This caused the scanner to remain paused and made it seem like it wasn’t scanning again.
Here’s the fixed full HomePageViewModel.cs code:
namespace Scan2Cart.ViewModels;
public partial class HomePageViewModel(IPageService pageService, IDataProvider dataProvider) : BaseViewModel(pageService) {
[ObservableProperty]
public partial bool ShouldDetect { get; set; } = true;
[ObservableProperty]
public partial bool _IsProductInfoVisible { get; set; } = false;
[ObservableProperty]
public partial Product Product { get; set; }
[ObservableProperty]
public partial bool PopUpDetectedOpen { get; set; }
public ObservableCollection<Product> Products { get; set; } = new ObservableCollection<Product>();
[RelayCommand]
private async Task BarcodesDetected(IEnumerable<BarcodeResult> results) {
var val = results.FirstOrDefault()?.Value;
if (string.IsNullOrEmpty(val))
return;
var product = await dataProvider.GetProductByIdAsync(val);
Product = product;
ShouldDetect = false;
PopUpDetectedOpen = true;
}
[RelayCommand]
void Yes() {
if (!Products.Any(x => x.Id == Product.Id)) {
Products.Add(Product);
}
// Close popup and resume detection
PopUpDetectedOpen = false;
ShouldDetect = true;
}
[RelayCommand]
void No() {
// Close popup and resume detection
PopUpDetectedOpen = false;
ShouldDetect = true;
}
[RelayCommand]
void Opening() {
_IsProductInfoVisible = true;
}
[RelayCommand]
void Closing() {
// Ensure popup is closed and camera detection resumes
_IsProductInfoVisible = false;
PopUpDetectedOpen = false;
ShouldDetect = true;
}
}
Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.