qr_code_to_image 0.0.3 copy "qr_code_to_image: ^0.0.3" to clipboard
qr_code_to_image: ^0.0.3 copied to clipboard

QR_Code_to_Image is a Flutter plugin that provides a range of features for working with QR codes. With this plugin, you can easily generate QR codes, display them on the screen, convert them into imag [...]

example/lib/main.dart

// ignore_for_file: use_build_context_synchronously

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:qr_code_to_image/qr_code_to_image.dart';
import 'package:url_launcher/url_launcher.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final TextEditingController textQr = TextEditingController();
  String qrCodeResult = "";
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text("Convert Qr code to image"),
        ),
        body: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.only(left: 15.0,right: 15.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                const SizedBox(height: 150),
                TextFormField(
                  controller: textQr,
                  minLines: 1,
                  maxLines: 10,
                  style:const TextStyle(color: Colors.black),
                  decoration: const InputDecoration(
                    hintText: "Enter your text",
                    label: Text("Enter your text"),
                    labelStyle: TextStyle(
                      color: Colors.black,
                      fontSize: 14,
                      fontWeight: FontWeight.w500,
                    ),
                    enabledBorder: OutlineInputBorder(
                      borderRadius: BorderRadius.all(Radius.circular(8)),
                      borderSide: BorderSide(color: Colors.pink),
                    ),
                    focusedBorder: OutlineInputBorder(
                      borderRadius: BorderRadius.all(Radius.circular(8)),
                      borderSide: BorderSide(color: Colors.pink),
                    ),
                  ),
                ),
                const SizedBox(height: 25),
                // Generate Qr code
                GestureDetector(
                  onTap: (){
                    QrCodeToImage.showQrCodeScreen(context, textQrCode: textQr.text.trim(),textButton: "Convert Qr code to image and share", colorWidgetTest: Colors.pink);
                  },
                  child: Container(
                    height: 50,
                    color: Colors.pink,
                    child: const Center(
                      child: Text("Generate Qr code",
                        style: TextStyle(
                            fontSize: 16,
                            color: Colors.white
                        ),
                      ),
                    ),
                  ),
                ),
                const SizedBox(height: 40),
                // Scan Qr code
                GestureDetector(
                  onTap: () {
                    QrCodeToImage.scanQrCode(lineColor: "#ff6666",cancelButtonText: "Anuler").then((value) {
                      if(value!.isNotEmpty){
                        setState(() {
                          qrCodeResult = value;
                        });
                      }
                    });
                  },
                  child: Container(
                    height: 50,
                    decoration: BoxDecoration(
                        border: Border.all(color: Colors.pink, width: 1)
                    ),
                    child: const Center(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Icon(Icons.qr_code_scanner, color: Colors.pink),
                          SizedBox(width: 10),
                          Text("Scan QR Code", style: TextStyle(color: Colors.pink)),
                        ],
                      ),
                    ),
                  ),
                ),
                const SizedBox(height: 40),
                // Scan BarCode code
                GestureDetector(
                  onTap: () {
                    QrCodeToImage.scanBarCode(lineColor: "#ff6666",cancelButtonText: "Anuler").then((value) {
                      if(value!.isNotEmpty){
                        setState(() {
                          qrCodeResult = value;
                        });
                      }
                    });
                  },
                  child: Container(
                    height: 50,
                    color: Colors.pinkAccent,
                    child: const Center(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Icon(Icons.qr_code_scanner, color: Colors.white),
                          SizedBox(width: 10),
                          Text("Scan BarCode", style: TextStyle(color: Colors.white)),
                        ],
                      ),
                    ),
                  ),
                ),
                // Display Qr code and copied
                if(qrCodeResult.isNotEmpty)...[
                  const SizedBox(height: 20),
                  SelectableText(
                    qrCodeResult,
                    textAlign: TextAlign.center,
                    style: const TextStyle(
                      color: Colors.blue,
                      decoration: TextDecoration.underline,
                    ),
                    onTap: () {
                      if (qrCodeResult.isNotEmpty && qrCodeResult.startsWith("http")) {
                        launchUrl();
                      }
                    },
                  ),
                  const SizedBox(height: 20),
                  ElevatedButton(
                    onPressed: qrCodeResult.isNotEmpty ? copyResult : null,
                    child: const Text("Copy Result", style: TextStyle(color: Colors.pink)),
                  ),
                ],
              ],
            ),
          ),
        )
    );
  }
  void launchUrl() async {
    if (await canLaunchUrl(Uri.parse(qrCodeResult))) {
      await launch(qrCodeResult);
    } else {
      ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Invalid URL')));
    }
  }

  void copyResult() {
    Clipboard.setData(ClipboardData(text: qrCodeResult));
    ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Text copied to clipboard')));
  }
}
4
likes
130
points
32
downloads

Publisher

unverified uploader

Weekly Downloads

QR_Code_to_Image is a Flutter plugin that provides a range of features for working with QR codes. With this plugin, you can easily generate QR codes, display them on the screen, convert them into images, and share them with other users. Additionally, you have the ability to scan existing QR codes and copy their content.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_barcode_scanner, flutter_web_plugins, path_provider, plugin_platform_interface, qr_flutter, share

More

Packages that depend on qr_code_to_image