Home > database >  Datastore plugin has not been added to amplify Flutter
Datastore plugin has not been added to amplify Flutter

Time:10-02

I follow the Amplify tutorial to make a todo app and got this error in return on the fist run anyone know why ? I have read another similar question on Stackoverflow but it didn't solve the problem for me so is there any other way. enter image description here

CodePudding user response:

The problem of your code is that it starts to use the DataStore without first initializing it.

The DataStore works as a plugin of the whole Amplify Flutter framework. So besides creating one DataStore plugin which you have done at line:47 of your code, you still have to plug the plugin to Amplify.

The solution is to move the creation of DataStore plugin into initState then add few more lines of code after that.

void initState(){

  // Your code of creating plugin
  final _dataStorePlugin = AmplifyDataStore(modelProvider: ModelProvide.instance)

  // add Amplify plugins
  Amplify.addPlugins([_dataStorePlugin]).then((_) {

    // configure Amplify
    //
    // note that Amplify cannot be configured more than once!
    return Amplify.configure(amplifyconfig);
});

}

Or follow the tutorial here

  • Related