The argument type 'QrImage' can't be assigned to the parameter type 'Widget?'
Asked Answered
R

1

6

The argument type 'QrImage' can't be assigned to the parameter type 'Widget?'.

Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('QR Code Generator'),
      ),
      body: Center(
        child: Container(
          child: QrImage(
            data: websiteUrl,
            version: QrVersions.auto,
            size: 200.0,
          ),
        ),
      ),
    );
  }

pubspec.yaml

qr_flutter: ^4.0.0 sdk: '>=3.0.6 <4.0.0'

Lowered sdk to below 2.12.0 to remove null check but error remains the same

Rite answered 11/8, 2023 at 19:4 Comment(3)
Welcome to SO! Taking a look at the docs. I think you might want to use QrImageView instead of QrImage. Does that make sense?Guilder
QrImage class is defined in dart package qr, and it is not a child of Widget class.Mel
QrImageView worked.Rite
B
1

I actually faced this problem

I found the solution on the library documentation on GitHub

Example Documentation Here

Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('QR Code Generator'),
      ),
      body: Center(
        child: Container(
          child: QrImageView(
            data: websiteUrl,
            version: QrVersions.auto,
            size: 200.0,
          ),
        ),
      ),
    );
  }

Just Replace QrImage To QrImageView

Bartholomew answered 16/10 at 7:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.