Flutter app crash after converting Provider 3 to 4

On Event Handlers like onPressed, OnTap, onLongPressed etc. we must use

Provider.of<T>(context,listen:false)

reason being that they will not listen for any update changes, instead are responsible for making changes.

whereas widgets like Text etc. are responsible for displaying...hence need to be updated on every change made....therefore use

Provider.of<T>(context,listen:true)  //by default is listen:true

listen:true being the default is logical.

It's not specifying inside an event handler that is not logical.listen: false

Also, 4.1.0 will somehow have a shorter alternative to Provider.of:

context.read<T>() // Provider.of<T>(context, listen: false)
context.watch<T>() // Provider.of<T>(context)

listen : false called when the data wouldn't updating any thing in the UI, and should be used, like removing all cards in a widget when button clicked.

For more info's, read this go_to_link


I have the same "problem", if i add listen: false everywhere i call Provider the problem is gone but i dont know if thats the right solution...?

Tags:

Flutter