It appears there may be some not-understood (by me) Flutter issue here.
I noticed the Backendless SDK guide for Flutter shows the initApp call in an
initState() override, so I rewrote by ‘plagiarizing’ the default counter app. InitState is a stateful class method so that’s where I put it. The app now completes the initApp call successfully, and (on button press) saves the data to the ‘Person’ table. Good experience, and useful for the following missions of retrieve, update, and delete.
The project is on Google Drive at
Main.dart is the working code, main_org.dart is the original code that gives the error. I know it’s not your job to ‘teach me Flutter’, but if you have time to look at it and let me know what you think, I’d appreciate it!
Jim
I haven’t tried running your project, but looked at its code.
I can assume your error is due to the save api call occurring before your application is initialised. Because you are using asynchronous operations.
You need to wait for initApp to complete its work.
Try the following:
Add the async keyword to your main: void main() async { // your code }
The return type of the initializeApp method must be Future. Future initializeApp() async { //your code }
On line 7, you need to add the await keyword before using this method. await initializeApp();
Thanks Nikita, appreciate you taking the time!
Going to finish the CRUD Rookie section with the working code, then work on this ‘bad’ code just for the troubleshooting experience.
Thanks again,
Jim