Mike Osborn
Mike Osborn

Reputation: 503

Problem related to change notifier provider in flutter

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

Answers (2)

Justus Lolwerikoi
Justus Lolwerikoi

Reputation: 873

In the class MyUser, add

extends ChangeNotifier

Such that it'll look like

class MyUser extends ChangeNotifier {}

Upvotes: 1

Eslam Ashraf
Eslam Ashraf

Reputation: 335

Just add with ChangeNotifier to MyUser class.

class MyUser with ChangeNotifier {}

Upvotes: 12

Related Questions