Search code examples
flutterqr-codefunc

generate qrcode with data and encrypted with key


I have to make a view where you see a qrCode. I have to write the function in the project in flutter and since we have the old project on Android Studio in Java, I wanted to try to take a cue from there. in Java the colleague before me encrypts a json containing (type ": 1," content ": email," display_name "," mac ") with a key that is passed on the basis of the user and generates the qr that is shown.

i found this flutter library which generates qrcode, qr_flutter but now how can I integrate it into the part I need? someone quò help me to write the function that generates me the qrcode with those 4 data in the json?


Solution

  • The data needed by QrImage widget is a String so you could do it like that:

    import 'dart:convert';
    
    Widget _buildQrCode() {
      Map<String,dynamic> myData = {
        'type': type,
        'content': content,
        'email': email,
        'mac': mac,
      };
    
      String encodedJson = jsonEncode(myData);
    
      return QrImage(
        data: encodedJson,
        version: QrVersions.auto,
        size: 320,
        gapless: false,
      );
    }