title: Flutter FetchData from API and save local with sqflite
body: <p>I have problem , went i'm fetch data from API and save to database local .
  So being a newbie in Flutter, I would like to find a way to save the data in a database for offline support.</p>
  
  <p>This the problem error</p>
  
  <pre><code>Unhandled Exception: type 'String' is not a subtype of type 'List&lt;dynamic&gt;' in type cast
  </code></pre>
  
  <p>My Model Data like this </p>
  
  <pre><code>List&lt;Employee&gt; employeeFromJson(String str) =&gt;
      List&lt;Employee&gt;.from(json.decode(str).map((x) =&gt; Employee.fromJson(x)));
  
  String employeeToJson(List&lt;Employee&gt; data) =&gt;
      json.encode(List&lt;dynamic&gt;.from(data.map((x) =&gt; x.toJson())));
  
  class Employee {
    int id;
    String id_surat;
    String nama;
    String nomor;
    String arti;
  
    Employee({
      this.id,
      this.id_surat,
      this.nama,
      this.nomor,
      this.arti,
    });
  
    factory Employee.fromJson(Map&lt;String, dynamic&gt; json) =&gt; Employee(
          id_surat: json["id_surat"],
          nama: json["nama"],
          nomor: json["nomor"],
          arti: json["arti"],
        );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
  
          "id_surat": id_surat,
          "nama": nama,
          "nomor": nomor,
          "arti": arti,
        };
  }
  </code></pre>
  
  <p>Here is the JSON parsing method that queries from the network:</p>
  
  <pre><code>class EmployeeApiProvider {
    Future&lt;List&lt;Employee&gt;&gt; getAllEmployees() async {
      var url = "EXAMPLE";
      Response response = await Dio().get(url);
      print(response.data);
  
      return (response.data as List).map((employee) {
        print('Inserting $employee');
        DBProvider.db.createEmployee(Employee.fromJson(employee));
      }).toList();
    }
  }
  </code></pre>
  
  <p>And Response from API Server , like this .</p>
  
  <pre><code>[
  {
  id_surat: "1",
  nama: "Al Fatihah",
  nomor: "1",
  arti: "Pembukaan"
  },
  {
  id_surat: "2",
  nama: "Al Baqarah",
  nomor: "2",
  arti: "Sapi Betina"
  },
  {
  id_surat: "3",
  nama: "Ali Imran",
  nomor: "3",
  arti: "Keluarga Imran"
  },
  {
  id_surat: "4",
  nama: "An Nisaa",
  nomor: "4",
  arti: "Wanita"
  },
  ]
  </code></pre>