Question: Actually, I want to update a flag in Db using a service call(Delete method) once the user close the browser. I am able to detect browser close action using `onbeforeunload` and `onunload` events but async call doesn't work for me(sometimes in debugging mode it works fine but on higher env it doesn't work).

Then, I tried to make sync request but then I found that Chrome now disallows synchronous XHR during page dismissal when the page is being navigated away from or closed by the user. 
check link : <https://www.chromestatus.com/feature/4664843055398912>

I have tried new `XMLHttpRequest()` as sync, fetch api also `Navigator.sendBeacon()` but unfortunately nothing works for me.

Please suggest something which works because I have visited so many posts but nothing works for me.

Thanks in advance.

Answer: 
Just filter the `List` only for the values higher or equal to your number and get the lowest value:

```dart
var n = 8; // Number to match
var l = [3, 7, 12, 19]; // List of values

var greater = l.where((e) => e >= n).toList()..sort(); //List of the greater values

print(greater.first); // Print the first value. -> 12

```
```
List<int> arr = [6, 12, 11, 18, 24,5,6,99,10,9];
    arr.sort((a, b) => a.compareTo(b));
    print(arr);
    print(Utils.getNextLargerNumber(8, arr));

```

and below is the logic:

```
static int getNextLargerNumber(int number, List<int> array)
  {
    for (var i = 0; i < array.length; i++) {
      if (number < array[i]) {
        return array[i];
      }
    }
    return -1;
  }

```