Hi, i have a question about using alerts in providers. For example, i have printService, which handles bluetooth connection and send data to bluetooth printer, is it ok to handle errors and display alerts for user right from the provider, or is it considered bad practise and i should create and present alerts only in components/pages?
Two years ago, I would have strongly discouraged displaying alerts from a provider. Today, the way things are architected in the framework, I feel much less strongly about it, but I don’t think there’s a single best answer. Instead, the question I would ask myself is “can I conceive of a situation somewhere down the line where I might want to be able to handle errors in more than one way?”. For example, let’s say there might be some sort of “batch job” feature that could get added later, in a way such that the provider can’t easily know whether a single request is part of a larger task or not. In that situation, users would typically not want to see “yo, I think the printer is out of paper” 20 times, so kicking error reporting up out of the provider and into the caller would seem to me more natural.
great answer as usual, thanks