title: rangeError (RangeError (index): Invalid value: Not in inclusive range 0..4: 5)
body: <p>So basically I'm making an Inventory Management System using flutter desktop.
  this is my code,</p>
  <p>InventoryPage.dart</p>
  <pre><code>    // get all posts
    Future&lt;void&gt; getData() async {
      Response response = await getInventoryMonthly(tanggal);
  
      if (response.error == null) {
        setState(() {
          _inventoryList = response.data as List;
          if(formattedLastDate == DateFormat('yyyy-MM-dd').format(DateTime(date.year, date.month+1, 0))){
            print(&quot;Benar!&quot;);
                }else{
              for (var i = 0; i &lt; _inventoryList.length; i++) {
                  addInventory(
                    _inventoryList[i]['id_kategori'], 
                    _inventoryList[i]['id_gudang'], 
                    _inventoryList[i]['id_brand'], 
                    _inventoryList[i]['nama'], 
                    _inventoryList[i]['parts_no'], 
                    _inventoryList[i]['new_parts'], 
                    _inventoryList[i]['satuan'], 
                    _inventoryList[i]['jumlah_akhir'], 
                    0.0,
                    0.0,
                    _inventoryList[i]['jumlah_akhir'], 
                    _inventoryList[i]['harga'], 
                    _inventoryList[i]['image'], 
                    tanggal,
                    ); 
                    }
                    print(formattedLastDate);
                    print(DateFormat('yyyy-MM-dd').format(DateTime(date.year, date.month+1, 0)));
                    // print(formattedLastDate);
                  print(&quot;salah!&quot;);
                }
  
          _loading = _loading ? !_loading : _loading;
        });
      } else if (response.error == unauthorized) {
        logOut().then((value) =&gt; {
              Navigator.of(context).pushAndRemoveUntil(
                  MaterialPageRoute(builder: (context) =&gt; Login()),
                  (route) =&gt; false)
            });
      } else {
        ScaffoldMessenger.of(context).showSnackBar(SnackBar(
          content: Text('${response.error}'),
        ));
      }
    }
  </code></pre>
  <p>AddInventory Future</p>
  <pre><code>// Add barang
  Future&lt;Response&gt; addInventory(
    int? id_kategori,
    int? id_gudang,
    int? id_brand,
    String? nama,
    var parts_no,
    var new_parts,
    var satuan,
    num? jumlah_awal,
    num? jumlah_masuk,
    num? jumlah_keluar,
    num? jumlah_akhir,
    num? harga,
    var image,
    var created_month,
  ) async {
    Response res = Response();
    try {
      String token = await getToken();
      final response = await http.post(Uri.parse(barangURL),
          headers: {
            'Accept': 'application/json',
            'Authorization': 'Bearer $token'
          },
          body: image != null
              ? {
                  &quot;id_kategori&quot;: id_kategori.toString(),
                  &quot;id_gudang&quot;: id_gudang.toString(),
                  &quot;id_brand&quot;: id_brand.toString(),
                  &quot;nama&quot;: nama,
                  &quot;parts_no&quot;: parts_no,
                  &quot;new_parts&quot;: new_parts,
                  &quot;satuan&quot;: satuan,
                  &quot;jumlah_awal&quot;: jumlah_awal.toString(),
                  &quot;jumlah_masuk&quot;: jumlah_masuk.toString(),
                  &quot;jumlah_keluar&quot;: jumlah_keluar.toString(),
                  &quot;jumlah_akhir&quot;: jumlah_akhir.toString(),
                  &quot;harga&quot;: harga.toString(),
                  &quot;image&quot;: image,
                  &quot;created_month&quot;: created_month,
                }
              : {
                  &quot;id_kategori&quot;: id_kategori.toString(),
                  &quot;id_gudang&quot;: id_gudang.toString(),
                  &quot;id_brand&quot;: id_brand.toString(),
                  &quot;nama&quot;: nama,
                  &quot;parts_no&quot;: parts_no,
                  &quot;new_parts&quot;: new_parts,
                  &quot;satuan&quot;: satuan,
                  &quot;jumlah_awal&quot;: jumlah_awal.toString(),
                  &quot;jumlah_masuk&quot;: jumlah_masuk.toString(),
                  &quot;jumlah_keluar&quot;: jumlah_keluar.toString(),
                  &quot;jumlah_akhir&quot;: jumlah_akhir.toString(),
                  &quot;harga&quot;: harga.toString(),
                  &quot;created_month&quot;: created_month.toString(),
                });
      switch (response.statusCode) {
        case 200:
          print(jsonDecode(response.body));
          res.data = jsonDecode(response.body);
          break;
        case 422:
          final errors = jsonDecode(response.body)['errors'];
          res.error = errors[errors.keys.elementAt(0)][0];
          break;
        case 401:
          res.error = unauthorized;
          break;
        default:
          res.error = somethingWentWrong;
          break;
      }
    } catch (e) {
      res.error = serverError;
    }
  
    return res;
  }
  
   
  </code></pre>
  <p>My goal is to simply make it so that flutter will automatically create Similiar Data and values at the end of the month. This is one of the error that I've got:
  <a href="https://i.stack.imgur.com/MaOnT.png" rel="nofollow noreferrer">rangeError (RangeError (index): Invalid value: Not in inclusive range 0..4: 5)</a></p>
  <p>Please can anyone help me with this?
  Thanks in advance</p>