Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Although there are no listeners, but the number of listeners is still greater than 0, is this normal? #889

Closed
lbgitjp opened this issue Sep 14, 2024 · 1 comment
Assignees
Labels
bug Something isn't working needs triage

Comments

@lbgitjp
Copy link

lbgitjp commented Sep 14, 2024

Describe the bug

The following code no one listen Counter's change, but print(context.read().hasListeners1) still output true.

To Reproduce

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class Counter with ChangeNotifier {
  int value = 0;

  bool get hasListeners1 => hasListeners;
}

void main() {
  runApp(
    ChangeNotifierProvider(
      create: (context) => Counter(),
      builder: (context, child) {
        print(context.read<Counter>().hasListeners1);

        return Container();
      },
    ),
  );
}

Expected behavior
In the code above, print(context.read().hasListeners1) should output false.

Thanks!

@lbgitjp lbgitjp added bug Something isn't working needs triage labels Sep 14, 2024
@rrousselGit
Copy link
Owner

There is a listener. The provider package is listening to the ChangeNotifier.
That's not possible to change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants