skip to Main Content

enter image description here

At first, I was told that PrettyQrView was wrong, so I changed PrettyQrView(qrCode: qrData) to PrettyQrView.data(data: qrData), and this error disappeared, but the error in else is still the same. I don’t know if it’s a location issue, but even if I move the location, the error remains the same.

I wanted to fix the error in else and create a code that generates a QR code containing the ID used when the user logs in.

2

Answers


  1. You can’t use if-else inside a collection. The only available control-flow operator that uses the keyword if is the collection if, that conditionally includes the element to the list.

    You might be looking for the conditional operator (known as ternary operator in other languages) instead.

    qrData.isNotEmpty
        ? PrettyQrView.data(data: qrData)
        : Text('There is ...')
    
    Login or Signup to reply.
  2. You have to remove the comma, so not

    if(qrData.isNotEmpty) ..., else
    

    but

    if(qrData.isNotEmpty) ... else
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search