How to use app state variable list in a custom function without resetting it?

When I am trying to do a custom function using a list of integers from the app state variable, how do I integrate the app state variable list without changing the integers already located there? When I use the following code, I think it is redefining it and resetting the list to nothing due to this code here: "integerlistofcardsremoved = [];"

int? randomintegernotinlist() {

  final List<int> integerlistofcardsremoved = [];
  final random = math.Random();
  int? randomNumber;
  do {
    randomNumber = random.nextInt(10) + 1;
  } while (integerlistofcardsremoved.contains(randomNumber));
  return randomNumber;

}
1
3 replies