validate method

Future<bool> validate(
  1. BuildContext context, {
  2. required List<KonamiCodeInput> inputHistory,
})

Matches the code and executes the callback if code is a match.

Implementation

Future<bool> validate(
  BuildContext context, {
  required List<KonamiCodeInput> inputHistory,
}) async {
  if (inputHistory.length < codes.length) {
    return false;
  }
  for (int index = 0; index < codes.length; index++) {
    final code = codes[index];
    final historyIndex = inputHistory.length - codes.length + index;
    final swipe = inputHistory[historyIndex];
    if (code != swipe) {
      return false;
    }
  }
  await onMatch(context);
  return true;
}