nfc_in_flutter
nfc_in_flutter copied to clipboard
QUESTION: How can I write a URL that launches the browser.
Hi, when I write a URL/URI to a tag, the URL/URI is first opened in the default text editor. I can click on it and it will opens the browser but I would like just open the link in the browser when I scan that tag.
This can definitely be done. If I use say "NFC Tools" or the "NXP Tagwriter" app it launches the URL/URI in the browser (and not in the default text editor).
I'm sure its something I am doing but can somebody please give some guidance on how to achieve this?
Cheers and thanks in advance, Vincent.
You can use NDEFRecord.uri(uri). This will launch the URL in browser
NDEFMessage newMessage = NDEFMessage.withRecords([
NDEFRecord.uri(Uri.parse(url_to_launch)),
]);
NDEFTag tag = await NFC
.writeNDEF(
newMessage,
once: true,
)
.first;