ChangeNotifierProxyProvider0 returns the error Failed assertion: line 125 pos 28: 'value.hasListeners != true': is not true

Viewed 351

I am not able to use ChangeNotifierProxyProvider.

I have a StreamBuilder (list of items) and I need to update a single item when something changes.
This is the part of the widget with ChangeNotifierProxyProvider:

return StreamBuilder<List<MyItem>>(
  stream: _listStream,
  builder: (context, snapshot) {
    switch (snapshot.connectionState) {
      case ConnectionState.waiting:
        return CircularProgressIndicator(strokeWidth: 3.0);
        break;
      default:
        if (snapshot.hasData && snapshot.data.length > 0) {
          return ListView.builder(
            padding: EdgeInsets.all(10.0),
            controller: _controller,
            itemCount: snapshot.data.length + 1,
            itemBuilder: (context, index) {
              return index >= snapshot.data.length
                  ? CircularProgressIndicator(strokeWidth: 3.0)
                  : ChangeNotifierProxyProvider0<MyItem>(
                create: (context) => snapshot.data[index],
                update: (_, item) => item,
                child: Consumer<MyItem>(
                  builder: (_, value, __) {
                    return ListTile(title: value.title);
                  },
                ),
              );
            },
          );
        } else {
          return Container();
        }
    }
  },
);

This is MyItem:

class MyItem with ChangeNotifier {
    String title;

    void changeTitle(newT) {
        title = newT;
        notifyListeners();
    }
}

In another part of the app I call myItem.changeTitle function.

The error I get is:

Another exception was thrown: 'package:provider/src/listenable_provider.dart': Failed assertion: line 125 pos 28: 'value.hasListeners != true': is not true.

The following assertion was thrown building Consumer<>(dirty, dependencies: [_InheritedProviderScope<>]):

UPDATE
It seems the error is:

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ A MyItem was used after being disposed.

Occurred in the line of Consumer definition

0 Answers
Related