automatically open link after scanning qr code flutter


I have a flutter application that I have added a qr code scanner package so that I can use it. How can I automatically open links after scanning a qr code. I used this package qr_code_scanner.

This is my code implementation

  Widget _buildQrView(BuildContext context) {
    // For this example we check how width or tall the device is and change the scanArea and overlay accordingly.
    var scanArea = (MediaQuery.of(context).size.width < 400 ||
            MediaQuery.of(context).size.height < 400)
        ? 220.0
        : 300.0;
    // To ensure the Scanner view is properly sizes after rotation
    // we need to listen for Flutter SizeChanged notification and update controller
    return QRView(
      key: qrKey,
      onQRViewCreated: onQRViewCreated,
      overlay: QrScannerOverlayShape(
          borderRadius: 10,
          borderLength: 30,
          borderWidth: 10,
          cutOutSize: scanArea),
      onPermissionSet: (ctrl, p) => _onPermissionSet(context, ctrl, p),

  onQRViewCreated(QRViewController qrViewController) {
    // this.qrViewController = qrViewController;
    qrViewController.scannedDataStream.listen((qrData) {
      final String qrCode = qrData.code;!.then(
        (value) => qrViewController.resumeCamera(),

  void _onPermissionSet(BuildContext context, QRViewController ctrl, bool p) {
    log('${}_onPermissionSet $p');
    if (!p) {
        SnackBar(content: Text('no Permission')),

I have implemented opening a new route after successfully scanning a qr code. I would like to know how I can open links after scanning their respective qr codes even if it is in webview.


After reading the link from the QR code use url_launcher to open the link :

void _launchURL() async =>
await canLaunch(_url) ? await launch(_url) : throw 'Could not launch $_url';

Answered By – Reham Alraee

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *