Posting JSON-formatted data
This is a recipe for a client web app that sends a request to a web server. The request contains the form's data that is posted in the JSON format.
How to do it...
Look at the project post_form
for the code.
Our form (refer the next diagram) will post data for a job in IT; we reuse the class
Job
in the Making toJSON and fromJSON methods in your class recipe from Chapter 4, Object Orientation. We keep the example short and simple, but add two new properties,posted
andopen
. Have a look at the following code:class Job { String type; int salary; String company; DateTime posted; // date of publication of job bool open = true; // is job still vacant ? Job(this.type, this.salary, this.company, this.posted); // toJSON and fromJSON methods }
The
model
class is made available to the code inpost_form.dart
using the following code:import '../model/job.dart';
We add our own event handler for the submit button using the following code:
void main() { querySelector...