Skip to content

Commit

Permalink
test qr embeded image implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jatindotdev authored Jan 21, 2024
1 parent 7ece442 commit d81742a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/components/qr_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:path_provider/path_provider.dart';
import 'package:kzlinks/utils/load_image.dart';

Future<void> showQRDialog(BuildContext context, String shortCode) async {
final kzillaUrl = 'https://kzilla.xyz/$shortCode';
// final imageUrl =
// 'https://chart.googleapis.com/chart?cht=qr&chs=500x500&chl=$kzillaUrl';

Future _shareQRImage() async {
final kzlogo = await loadImage(context, "assets/kz_logo.png")

final image = await QrPainter(
data: kzillaUrl,
version: QrVersions.auto,
gapless: true,
color: Colors.black,
embeddedImage: kzlogo,
emptyColor: Colors.white,
).toImageData(200.0); // Generate QR code image data

Expand Down Expand Up @@ -70,9 +72,10 @@ Future<void> showQRDialog(BuildContext context, String shortCode) async {
),
child: ClipRRect(
borderRadius: BorderRadius.circular(16),
child: QrImageView(
child: QrImage(
data: kzillaUrl,
version: QrVersions.auto,
embeddedImage: AssetImage("assets/kz_logo.png"),
size: 250,
),
)),
Expand Down
13 changes: 13 additions & 0 deletions lib/utils/load_image.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'dart:async';
import 'dart:ui' as ui;
import 'dart:typed_data';
import 'package:flutter/material.dart';

Future<ui.Image> loadImage(BuildContext context, String assetPath) async {
final ByteData data = await DefaultAssetBundle.of(context).load(assetPath);
final Completer<ui.Image> completer = Completer();
ui.decodeImageFromList(data.buffer.asUint8List(), (ui.Image img) {
return completer.complete(img);
});
return completer.future;
}

0 comments on commit d81742a

Please sign in to comment.