fluffychat/lib/widgets/qr_code_viewer.dart
ggurdin 49e586a7ad
Fluffychat merge (#1685)
chore: Merge upstream changes

---------

Signed-off-by: Krille <c.kussowski@famedly.com>
Co-authored-by: krille-chan <christian-kussowski@posteo.de>
Co-authored-by: Krille <c.kussowski@famedly.com>
Co-authored-by: Linerly <linerly@proton.me>
Co-authored-by: Priit Jõerüüt <hwlate@joeruut.com>
Co-authored-by: 大王叫我来巡山 <hamburger2048@users.noreply.hosted.weblate.org>
Co-authored-by: fadelkon <fadelkon@posteo.net>
Co-authored-by: Aindriú Mac Giolla Eoin <aindriu80@gmail.com>
Co-authored-by: Edgars Andersons <Edgars+Weblate@gaitenis.id.lv>
Co-authored-by: josé m <correoxm@disroot.org>
Co-authored-by: Bezruchenko Simon <worcposj44@gmail.com>
Co-authored-by: Christian <christian-pauly@posteo.de>
Co-authored-by: - <hitekex@yandex.ru>
Co-authored-by: Angelo Schirinzi <Odi-3@users.noreply.hosted.weblate.org>
Co-authored-by: xabirequejo <xabi.rn@gmail.com>
Co-authored-by: Piotr Orzechowski <piotr@orzechowski.tech>
Co-authored-by: Rex_sa <rex.sa@pm.me>
Co-authored-by: Tewuzij <tenajeza@outlook.com>
Co-authored-by: goknarbahceli <goknarbahceli@proton.me>
Co-authored-by: தமிழ்நேரம் <anishprabu.t@gmail.com>
Co-authored-by: Erin <erin@erindesu.cz>
Co-authored-by: EpicKiwi <me@epickiwi.fr>
Co-authored-by: Christian Tietze <me@christiantietze.de>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-02-03 12:36:46 -05:00

142 lines
4.4 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:image/image.dart';
import 'package:matrix/matrix.dart';
import 'package:pretty_qr_code/pretty_qr_code.dart';
import 'package:qr_image/qr_image.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pangea/common/config/environment.dart';
import 'package:fluffychat/utils/fluffy_share.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';
import '../config/themes.dart';
Future<void> showQrCodeViewer(
BuildContext context,
String content,
) =>
showDialog(
context: context,
builder: (context) => QrCodeViewer(content: content),
);
class QrCodeViewer extends StatelessWidget {
final String content;
const QrCodeViewer({required this.content, super.key});
void _save(BuildContext context) async {
final imageResult = await showFutureLoadingDialog(
context: context,
future: () async {
// #Pangea
// final inviteLink = 'https://matrix.to/#/$content';
final inviteLink = '${Environment.frontendURL}/#/rooms/$content';
// Pangea#
final image = QRImage(
inviteLink,
size: 256,
radius: 1,
).generate();
return compute(encodePng, image);
},
);
final bytes = imageResult.result;
if (bytes == null) return;
if (!context.mounted) return;
MatrixImageFile(
bytes: bytes,
name: 'QR_Code_$content.png',
mimeType: 'image/png',
).save(context);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final inviteLink = 'https://matrix.to/#/$content';
return Scaffold(
backgroundColor: Colors.black.withAlpha(128),
extendBodyBehindAppBar: true,
appBar: AppBar(
elevation: 0,
leading: IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.black.withAlpha(128),
),
icon: const Icon(Icons.close),
onPressed: Navigator.of(context).pop,
color: Colors.white,
tooltip: L10n.of(context).close,
),
backgroundColor: Colors.transparent,
actions: [
IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.black.withAlpha(128),
),
icon: Icon(Icons.adaptive.share_outlined),
onPressed: () => FluffyShare.share(
inviteLink,
context,
),
color: Colors.white,
tooltip: L10n.of(context).share,
),
const SizedBox(width: 8),
IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.black.withAlpha(128),
),
icon: const Icon(Icons.download_outlined),
onPressed: () => _save(context),
color: Colors.white,
tooltip: L10n.of(context).downloadFile,
),
const SizedBox(width: 8),
],
),
body: Center(
child: Container(
margin: const EdgeInsets.all(32.0),
padding: const EdgeInsets.all(32.0),
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ConstrainedBox(
constraints:
const BoxConstraints(maxWidth: FluffyThemes.columnWidth),
child: PrettyQrView.data(
data: inviteLink,
decoration: PrettyQrDecoration(
shape: PrettyQrSmoothSymbol(
roundFactor: 1,
color: theme.colorScheme.onPrimaryContainer,
),
),
),
),
const SizedBox(height: 8.0),
SelectableText(
content,
textAlign: TextAlign.center,
style: TextStyle(
color: theme.colorScheme.onPrimaryContainer,
fontSize: 12,
),
),
],
),
),
),
);
}
}