Created
February 26, 2020 11:39
-
-
Save Dviejopomata/3cfc1bda54bdb2b34f647f7da1b7575b to your computer and use it in GitHub Desktop.
Extraer tarjeta en flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final String creditPattern = r"(\d{4}) (\d{4}) (\d{4}) (\d{4})"; | |
final RegExp cardRegexp = RegExp(creditPattern); | |
final expPattern = r"(\d{2})\/(\d{2})"; | |
final expRegexp = RegExp(expPattern); | |
final VisionText visionText = | |
await textRecognizer.processImage(visionImage); | |
for (TextBlock block in visionText.blocks) { | |
for (TextLine line in block.lines) { | |
if (cardRegexp.hasMatch(line.text)) { | |
setState(() { | |
tarjetaCredito = line.text; | |
}); | |
} | |
if (expRegexp.hasMatch(line.text)) { | |
final allMatches = expRegexp.firstMatch(line.text); | |
final month = int.parse(allMatches.group(1)); | |
final year = int.parse(allMatches.group(2)); | |
setState(() { | |
expMonth = month; | |
expYear = year; | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment