'Flutter: How to catch "Scheme not starting with alphabetic character (at character 1)"
I have a text field where I can paste text. I use this to paste URL's from the internet. If I accidentally paste a large chunk of code from my clipboard instead of normal text or URL's, it gives me the following error: Scheme not starting with alphabetic character (at character 1).
How can I catch this error so that the user has a good experience?
[EDIT]
There is a button with a clipboard icon that the user can tap. Here is where the error happens once this button is tapped by the user:
onTap: () async {
if (linkTextController.text.trim() == "") {
try {
ClipboardData? data = await Clipboard.getData(Clipboard.kTextPlain);
linkTextController.text = data!.text.toString();
} catch (error) {
print(error);
}
} else {
linkTextController.text = "";
}
setState(() {});
},
Solution 1:[1]
Try handling the onChanged event of the TextField using official document - Handle changes to a text field
UPDATE
You might want to use hasStrings() first, given here, because the official documentation for ClipboardData class clearly states that:<br /
The system clipboard can contain data of various media types. This data structure currently supports only plain text data, in the text property.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
