-
Notifications
You must be signed in to change notification settings - Fork 2
Communicating with the Server
Requests are written in client.dart. A request function is asynchronous, and returns a Future<Response> object. Technically, if we directly return the response without await, the function is still effectively asynchronous (so this might be redundant).
You need to add a model in order to parse a JSON response from the server. Create a *.dart in /models, then head to here to find out how to auto-generate the JSON serialization/deserialization code.
When sending a request that parses JSON data, import your model and invoke the Class.fromJson() static function.
You might have noticed InheritedClient in actions.dart. This is basically a state container that can be passed down widgets, so our main widget's state is inherited and passed down. This is important because we need to call login() and register() from ancestor widgets.
Use Client.get() to get a static instance of Client. Make sure you add a model if you're trying to parse a response from the server. Image uploads are handled using multipart form requests.