title: State not updating in a List, Flutter Provider
body: <p>When I try to update a list, I have 2 issues, one method (Method 1 below) only updates the data I'm passing and the rest of the data is <code>null</code> and I have the error <code>Null check operator used on a null value</code>, so my widget breaks when I listen to changes. The other method (Method 2 below) has issues because I can not specify where in the list should I update the data and I get an error <code>Illegal assignment to non-assignable expression. Missing selector such as '.identifier' or '[0]'. Try adding a selector.</code> So I'm not sure what do now, what am I missing. The code:</p>
  <p>Method 1:</p>
  <pre><code>List&lt;ItemData&gt;? _items = [];
  
  List&lt;ItemData&gt;? get items =&gt; _items;
  
  //Updates only the price and the other data in the state goes null
  updatePrice(ItemData price) {
      _items![_items!.indexWhere((element) =&gt; element.itemId == price.itemId)] = price;
      notifyListeners();
    }
  
  </code></pre>
  <p>Method 2:</p>
  <pre><code>List&lt;ItemData&gt;? _items = [];
  
  List&lt;ItemData&gt;? get items =&gt; _items;
  
  updatePrice(ItemData price) {
  // I can't use this since I have to add an selector and I don't understand how
      _items!.firstWhere((element) =&gt; element.itemId == price.itemId) = price;
      notifyListeners();
    }
  </code></pre>
  <p>The API call:</p>
  <pre><code> Future&lt;ItemData&gt; patchFee(
        currency, fee, itemId, transactionId) async {
      final response = await (ApiRequest(Method.PATCH, '/items',
          body: jsonEncode({
            &quot;itemId&quot;: itemId,
            &quot;transactionId&quot;: transactionId,
            &quot;fees&quot;: [
              {
                &quot;currency&quot;: currency,
                &quot;type&quot;: &quot;EXPENSE&quot;,
                &quot;fee&quot;: fee,
                &quot;description&quot;: &quot;Item price&quot;,
              }
            ],
          })));
      Map&lt;String, dynamic&gt; jsonDecodedResponse =
          jsonDecode(utf8.decode(response!.bodyBytes));
      var list = jsonDecodedResponse['data']['fees'] as List;
      List&lt;Fees&gt; feesList = list.map((i) =&gt; Fees.fromJson(i)).toList();
      return ItemData(
        itemId: jsonDecodedResponse['data']['itemId'],
        transactionId: jsonDecodedResponse['data']['transactionId'],
        fees: feesList,
      );
    }
  
  </code></pre>
  <p>Action for the API call:</p>
  <pre><code>final itemStore = Provider.of&lt;ItemStore&gt;(context, listen: true);
  
  ...
  
  TextButton(
              style: TextButton.styleFrom(
                textStyle: const TextStyle(fontSize: 20),
              ),
              onPressed: () async {
         final response = await patchFee(
        USD, 300, 123, 333);
  
        itemStore.updatePrice(response);
  },
              child: const Text('Update Price'),
            ),
  </code></pre>
  <p>The patch goes through with status 200, I listen to the changes with final <code>itemStore = Provider.of&lt;ItemStore&gt;(context, listen: true);</code>, so I assume the error is that I'm updating the state with my <code>updatePrice(price)</code> method wrong, but can't seem to figure it out what and why.
  Thanks you in advance for the help.</p>