Is it safe to pass buildContext in flutter as a parameter to a family provider using flutter riverpod?
2
Don’t pass build context in the riverpod. Build context should be local to the screen. Don’t make it global.
Is it safe? Yes. Nothing terrible will happen
Is it a bad practice? Also yes. Your providers should be independent from the UI. And relying on BuildContext may make it difficult to obtain your provider’s state in a different place.
BuildContext
Click here to cancel reply.
2
Answers
Don’t pass build context in the riverpod. Build context should be local to the screen. Don’t make it global.
Is it safe? Yes. Nothing terrible will happen
Is it a bad practice? Also yes. Your providers should be independent from the UI. And relying on
BuildContext
may make it difficult to obtain your provider’s state in a different place.