I'm getting this error message:
Unhandled Exception: A ModeManager was used after being disposed.
I'm using ChangeNotifier (class ModeManager) together with ChangeNotifierProvider. Build method, where I create Provider looks like this:
@override
Widget build(BuildContext context) {
return !_isLoaded ? Center(child: CircularProgressIndicator()) : ChangeNotifierProvider(
create: (_) => ModeManager(_appUser),
child: Scaffold(
appBar: AppBar(
title: Text('Connect Spotify'),
),
body: AddSpotifyScreenBody(),
),
);
}
Widget where I use provider looks something like this:
class _AddSpotifyScreenBodyState extends State<AddSpotifyScreenBody> {
@override
Widget build(BuildContext context) {
var provider = Provider.of<ModeManager>(context);
return Center(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text(provider.isCollecting ? 'COLLECTING NOW' : 'SHARING NOW'),
//...some other widgets using provider...
],
),
),
);
}
}
Does anybody know what could cause this error or what am I doing wrong? Thank You very much.