退出页面颤动时保存在共享首选项中

Save in shared preference while exit page flutter

我试图在退出页面时将 INT 值保存在共享首选项中。所以我用dispose方法保存但是报错

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<AuthProvider>(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: PlayPage(dependencies: [_InheritedProviderScope<AuthProvider>, MediaQuery], 
   state: _PlayPageState#d7691(lifecycle state: defunct))
    'package:provider/src/provider.dart':
       Failed assertion: line 242 pos 7: 'context.owner.debugBuilding ||
      listen == false ||
      debugIsInInheritedProviderUpdate'

代码:

 @override
void dispose() {


Provider.of<AuthProvider>(context).storeVideoTiming( _duration?.inSeconds ?? 0);
 super.dispose();

 }

提供商页面:

 storeVideoTiming(int timins) async{

   SharedPreferences prefs = await SharedPreferences.getInstance();

   prefs.setInt('VideoCount', timins);
    }

只需更改此行:

Provider.of<AuthProvider>(context).storeVideoTiming( _duration?.inSeconds ?? 0);

与 :

Provider.of<AuthProvider>(context, listen: false).storeVideoTiming( _duration?.inSeconds ?? 0);