Reputation: 503
I am getting an error when using changenotifierprovider
in my flutter project.
Error:
'MyUser' doesn't conform to the bound 'ChangeNotifier?' of the type parameter 'T'. Try using a type that is or is a subclass of 'ChangeNotifier?'.
Class:
class SettingsForm extends StatefulWidget {
static Widget getWidget() {
return new Provider(
create: (_) => MyUser(uid: ''),
child: ChangeNotifierProvider( <-- here **ChangeNotifierProvider**
create: (BuildContext context) => MyUser(uid: ''),
builder: (_, _) => SettingsForm()),
)
);
}
Upvotes: 7
Views: 4503
Reputation: 873
In the class MyUser, add
extends ChangeNotifier
Such that it'll look like
class MyUser extends ChangeNotifier {}
Upvotes: 1
Reputation: 335
Just add with ChangeNotifier
to MyUser
class.
class MyUser with ChangeNotifier {}
Upvotes: 12