[Flutter] Tried to listen to a value exposed with provider, from outside of the widget tree.

하스레·2022년 9월 5일
0

오류 설명

The following assertion was thrown while handling a gesture:
Tried to listen to a value exposed with provider, from outside of the widget tree.

This is likely caused by an event handler (like a button's onPressed) that called
Provider.of without passing `listen: false`.

To fix, write:
Provider.of<MyExchangesViewModel>(context, listen: false);

It is unsupported because may pointlessly rebuild the widget associated to the
event handler, when the widget tree doesn't care about the value.

The context used was: _ViewFilter(dependencies: [_LocalizationsScope-[GlobalKey#8ddd0], _InheritedProviderScope<MyExchangesViewModel?>])
'package:provider/src/provider.dart':
package:provider/src/provider.dart:1
Failed assertion: line 274 pos 7: 'context.owner!.debugBuilding ||
          listen == false ||
          debugIsInInheritedProviderUpdate'

오류 해결

provider 버전 6을 사용할 때, 프로바이더 내부 데이터를 수정하려면 listen: false를 넘겨줘야한다.


https://stackoverflow.com/questions/60083895/tried-to-listen-to-a-value-exposed-with-provider-from-outside-of-the-widget-tre

profile
Software Developer

0개의 댓글