[FIXED] Why Provider.of<> doesn't work without `listen: false`?


I’ve simple widget tree, and try to figure out why Provider.of<>() doesn’t work in the GestureDetector, onTap() callback.

This is my model:

class ShareObject {
  int intField;


class ShareObjectProvider extends ShareObject with ChangeNotifier {

  void increment() {

Here is my simple tree, where I try to invoke method from model:

class ParentWidgetState extends State<ParentWidget> {
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (context) => ShareObjectProvider(0),
      child: Scaffold(
        body: const WidgetThree(),

class WidgetThree extends StatelessWidget {
  const WidgetThree({Key? key}) : super(key: key);

  Widget build(BuildContext context) {
    return Center(
      child: SizedBox(
        width: 200,
        height: 200,
        child: Container(
          color: Colors.deepOrange,
          child: Center(
              child: GestureDetector(
                onTap: () =>
                child: Text(
                  "Test ${Provider.of<ShareObjectProvider>(context).intField}",
                  style: const TextStyle(color: Colors.blueAccent),

Why when I change to Provider.of<ShareObjectProvider>(context, listen: false).increment() it start working correctly?


As per documentation,


works like a watch, which makes the widget to rebuild again

listen: false

makes it work like read

in your case:

late ShareObjectProvider provider;

void initState() {

  provider = Provider.of<ShareObjectProvider>(listen: false);

then use it in your GestureDetector

here’s the link for provider’s documentation where the above said things are mentioned

Answered By – iamdipanshus

Answer Checked By – Candace Johnson (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published