QR CODE Generator Modification

General Conversations

Hello to everyone,
I added Qr Code generator code below from Pub.dev and I need some modifications. I am zero at Flutter, unfortunately.

In the default version; it asks for the text or URL and has generate button to process the QR.
I need to add a parameter in FF custom widget area for username instead of text input and to generate the QR code automatically instead of onPressed option.

But I do not know how to add 'username' parameter into the code. And generate it automatically.

Anybody can help me about this modification?

Thanks in advance

// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/widgets/index.dart'; // Imports other custom widgets
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:qr_flutter/qr_flutter.dart';

class Qrcode extends StatefulWidget {
  const Qrcode({
    Key? key,
    this.width,
    this.height,
  }) : super(key: key);

  final double? width;
  final double? height;

  @override
  _QrcodeState createState() => _QrcodeState();
}

class _QrcodeState extends State<Qrcode> {
  TextEditingController qrCodeController = TextEditingController();
  String qrData = '';

  @override
  void dispose() {
    qrCodeController.dispose();
    super.dispose();
  }

  void generateQrCode() {
    setState(() {
      qrData = qrCodeController.text;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          TextFormField(
            controller: qrCodeController,
            decoration: InputDecoration(
                hintText: 'username.womron.de',
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(20),
                )),
          ),
          const SizedBox(
            height: 50,
          ),
          QrImageView(
            data: qrData,
            version: QrVersions.auto,
            size: 200.0,
          ),
          SizedBox(
            height: 40,
          ),
          Container(
            width: 160,
            height: 45,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(4),
              color: Colors.green,
            ),
            child: MaterialButton(
                onPressed: generateQrCode, child: Text("Create QR Code")),
          ),
        ],
      ),
    );
  }
}





2 replies