Using this tutorial. Had to install dart to get the pub command.
Tutorial on customizing zsh (in case I want to do that later).
Added the directory where pub installs all of its executables to PATH (in ~/.zshrc )
You can then refresh the terminal to use the newly changed config file without closing and reopening it with “source $HOME/.zshrc”
“aqueduct serve” crashed with an IsolateSpawnException. Running “flutter pub upgrade” did not fix it. What *did* fix it is navigating into the aqueduct project folder. It was having trouble finding my pubspec.yaml file.
If you get “Error: Getter not found: ‘defaultType’. ” with aqueduct serve, try “pub run aqueduct serve” instead.
It seems like any files that you want to import into channel.dart need to be located somewhere in or under the lib folder. Using ‘..’ in your import path just gets you ‘package:’ instead of the project folder.
Notice we are using @Bind.path('id') int id as the input parameter. This is to declare our input parameter which is path('id') and bind it as argument of type integer for the method getHeroByID.
With that, we can pull the entire list or a single entry. Next is to make it work with Postgres instead of a hard-coded list.
I seem to have successfully applied the aqueduct migration file, but when I run “aqueduct serve” it is still pulling from the old list of heroes instead of the newly generated one. There’s probably a step missing from the tutorial.
Thanks to this tutorial series on youtube I was able to figure out what was missing. I needed a data model for the data, and code to actually fetch the data from the database instead of from the hardcoded list. It seems that the Flutter tutorial left that part out entirely, though thankfully their GitHub included the correct code.
Starting the database:
pg_ctl -D /usr/local/var/postgres start
psql postgres
postgres-# \c database-name
postgres=# \q
aqueduct serve
Implementing the commands was easy enough, except for put. The problem wasn’t with put itself; but the application used to test in the tutorial doesn’t send a proper put request. Using Postman instead fixed that issue.
Implementing everything in a flutter app ran into issues when testing on the android emulator. Localhost on the emulator just tries to go to the emulated machine. Solved the issue by changing the url used in the app to the actual ip address of the machine, and setting the android emulator’s proxy to the same (with the port of the aqueduct server). Make sure to actually close and reopen the emulator after doing this! A hot reload or restart is not good enough.
Additionally, since the id (primary key) used for put is in the path, you do not need to include it in the body. (in fact, since it’s a managed primary key, you should *not* include it in the body, as you’ll just confuse the database).
When updating, the change doesn’t display immediately. Sometimes you have to tap on an item and back out to re-render the list, and only then can you see the change. I’d like to figure out a way to fix that; either delay the rendering of the list screen after sending a request, or notify the screen when the request returns that it should re-render.
Postgres Exercises for later!