void _updateLists()

in lib/studies/shrine/expanding_bottom_sheet.dart [638:669]


  void _updateLists() {
    // Update _internalList based on the model
    _internalList =
        ScopedModel.of<AppStateModel>(context).productsInCart.keys.toList();
    final internalSet = Set<int>.from(_internalList);
    final listSet = Set<int>.from(_list.list);

    final difference = internalSet.difference(listSet);
    if (difference.isEmpty) {
      return;
    }

    for (final product in difference) {
      if (_internalList.length < _list.length) {
        _list.remove(product);
      } else if (_internalList.length > _list.length) {
        _list.add(product);
      }
    }

    while (_internalList.length != _list.length) {
      var index = 0;
      // Check bounds and that the list elements are the same
      while (_internalList.isNotEmpty &&
          _list.length > 0 &&
          index < _internalList.length &&
          index < _list.length &&
          _internalList[index] == _list[index]) {
        index++;
      }
    }
  }