mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-23 02:54:30 +00:00
desktop save receiving qr image to file
This commit is contained in:
parent
a35e6e8d97
commit
1b5ced5061
1 changed files with 49 additions and 12 deletions
|
@ -1,9 +1,11 @@
|
||||||
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
// import 'package:document_file_save_plus/document_file_save_plus.dart';
|
// import 'package:document_file_save_plus/document_file_save_plus.dart';
|
||||||
import 'package:decimal/decimal.dart';
|
import 'package:decimal/decimal.dart';
|
||||||
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
|
@ -71,19 +73,53 @@ class _GenerateUriQrCodeViewState extends State<GenerateUriQrCodeView> {
|
||||||
await image.toByteData(format: ui.ImageByteFormat.png);
|
await image.toByteData(format: ui.ImageByteFormat.png);
|
||||||
Uint8List pngBytes = byteData!.buffer.asUint8List();
|
Uint8List pngBytes = byteData!.buffer.asUint8List();
|
||||||
|
|
||||||
// if (shouldSaveInsteadOfShare) {
|
if (shouldSaveInsteadOfShare) {
|
||||||
|
if (Util.isDesktop) {
|
||||||
|
final dir = Directory("${Platform.environment['HOME']}");
|
||||||
|
if (!dir.existsSync()) {
|
||||||
|
throw Exception(
|
||||||
|
"Home dir not found while trying to open filepicker on QR image save");
|
||||||
|
}
|
||||||
|
final path = await FilePicker.platform.saveFile(
|
||||||
|
fileName: "qrcode.png",
|
||||||
|
initialDirectory: dir.path,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (path != null) {
|
||||||
|
final file = File(path);
|
||||||
|
if (file.existsSync()) {
|
||||||
|
unawaited(
|
||||||
|
showFloatingFlushBar(
|
||||||
|
type: FlushBarType.warning,
|
||||||
|
message: "$path already exists!",
|
||||||
|
context: context,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await file.writeAsBytes(pngBytes);
|
||||||
|
unawaited(
|
||||||
|
showFloatingFlushBar(
|
||||||
|
type: FlushBarType.success,
|
||||||
|
message: "$path saved!",
|
||||||
|
context: context,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// await DocumentFileSavePlus.saveFile(
|
// await DocumentFileSavePlus.saveFile(
|
||||||
// pngBytes,
|
// pngBytes,
|
||||||
// "receive_qr_code_${DateTime.now().toLocal().toIso8601String()}.png",
|
// "receive_qr_code_${DateTime.now().toLocal().toIso8601String()}.png",
|
||||||
// "image/png");
|
// "image/png");
|
||||||
// } else {
|
}
|
||||||
|
} else {
|
||||||
final tempDir = await getTemporaryDirectory();
|
final tempDir = await getTemporaryDirectory();
|
||||||
final file = await File("${tempDir.path}/qrcode.png").create();
|
final file = await File("${tempDir.path}/qrcode.png").create();
|
||||||
await file.writeAsBytes(pngBytes);
|
await file.writeAsBytes(pngBytes);
|
||||||
|
|
||||||
await Share.shareFiles(["${tempDir.path}/qrcode.png"],
|
await Share.shareFiles(["${tempDir.path}/qrcode.png"],
|
||||||
text: "Receive URI QR Code");
|
text: "Receive URI QR Code");
|
||||||
// }
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint(e.toString());
|
debugPrint(e.toString());
|
||||||
}
|
}
|
||||||
|
@ -567,6 +603,7 @@ class _GenerateUriQrCodeViewState extends State<GenerateUriQrCodeView> {
|
||||||
desktopMed: true,
|
desktopMed: true,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
// TODO: add save functionality instead of share
|
// TODO: add save functionality instead of share
|
||||||
|
// save works on linux at the moment
|
||||||
await _capturePng(true);
|
await _capturePng(true);
|
||||||
},
|
},
|
||||||
label: "Save",
|
label: "Save",
|
||||||
|
|
Loading…
Reference in a new issue