mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-17 06:20:44 +01:00
chore: Migrate to mobile scanner
This fixes qr code scanner on iOS and also adds QR Code scanner support to macOS and web.
This commit is contained in:
parent
8f56687d43
commit
308dadb446
@ -8,6 +8,7 @@ import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:fluffychat/pages/new_private_chat/new_private_chat_view.dart';
|
||||
import 'package:fluffychat/pages/new_private_chat/qr_scanner_modal.dart';
|
||||
import 'package:fluffychat/utils/fluffy_share.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/utils/url_launcher.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
@ -28,6 +29,9 @@ class NewPrivateChatController extends State<NewPrivateChat> {
|
||||
|
||||
bool get hideFab => _hideFab;
|
||||
|
||||
bool get scanningSupported =>
|
||||
PlatformInfos.isMobile || PlatformInfos.isWeb || PlatformInfos.isMacOS;
|
||||
|
||||
static const Set<String> supportedSigils = {'@', '!', '#'};
|
||||
|
||||
static const String prefix = 'https://matrix.to/#/';
|
||||
@ -76,16 +80,18 @@ class NewPrivateChatController extends State<NewPrivateChat> {
|
||||
);
|
||||
|
||||
void openScannerAction() async {
|
||||
final info = await DeviceInfoPlugin().androidInfo;
|
||||
if ((info.version.sdkInt ?? 16) < 21) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
L10n.of(context)!.unsupportedAndroidVersionLong,
|
||||
if (PlatformInfos.isAndroid) {
|
||||
final info = await DeviceInfoPlugin().androidInfo;
|
||||
if ((info.version.sdkInt ?? 16) < 21) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
L10n.of(context)!.unsupportedAndroidVersionLong,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
await Permission.camera.request();
|
||||
await showModalBottomSheet(
|
||||
|
@ -8,7 +8,6 @@ import 'package:vrouter/vrouter.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pages/new_private_chat/new_private_chat.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
@ -102,7 +101,7 @@ class NewPrivateChatView extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: PlatformInfos.isMobile && !controller.hideFab
|
||||
floatingActionButton: controller.scanningSupported && !controller.hideFab
|
||||
? FloatingActionButton.extended(
|
||||
onPressed: controller.openScannerAction,
|
||||
label: Text(L10n.of(context)!.scanQrCode),
|
||||
|
@ -1,10 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:qr_code_scanner/qr_code_scanner.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
|
||||
import 'package:fluffychat/utils/url_launcher.dart';
|
||||
|
||||
@ -16,19 +13,6 @@ class QrScannerModal extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _QrScannerModalState extends State<QrScannerModal> {
|
||||
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
|
||||
QRViewController? controller;
|
||||
|
||||
@override
|
||||
void reassemble() {
|
||||
super.reassemble();
|
||||
if (Platform.isAndroid) {
|
||||
controller!.pauseCamera();
|
||||
} else if (Platform.isIOS) {
|
||||
controller!.resumeCamera();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@ -40,36 +24,15 @@ class _QrScannerModalState extends State<QrScannerModal> {
|
||||
),
|
||||
title: Text(L10n.of(context)!.scanQrCode),
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
QRView(
|
||||
key: qrKey,
|
||||
onQRViewCreated: _onQRViewCreated,
|
||||
overlay: QrScannerOverlayShape(
|
||||
borderColor: Theme.of(context).primaryColor,
|
||||
borderRadius: 10,
|
||||
borderLength: 30,
|
||||
borderWidth: 8,
|
||||
),
|
||||
),
|
||||
],
|
||||
body: MobileScanner(
|
||||
controller: MobileScannerController(),
|
||||
onDetect: _onDetect,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onQRViewCreated(QRViewController controller) {
|
||||
this.controller = controller;
|
||||
late StreamSubscription sub;
|
||||
sub = controller.scannedDataStream.listen((scanData) {
|
||||
sub.cancel();
|
||||
Navigator.of(context).pop();
|
||||
UrlLauncher(context, scanData.code).openMatrixToUrl();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller?.dispose();
|
||||
super.dispose();
|
||||
void _onDetect(Barcode barcode, MobileScannerArguments? args) {
|
||||
Navigator.of(context).pop();
|
||||
UrlLauncher(context, barcode.rawValue).openMatrixToUrl();
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import flutter_web_auth
|
||||
import flutter_webrtc
|
||||
import geolocator_apple
|
||||
import just_audio
|
||||
import mobile_scanner
|
||||
import package_info
|
||||
import package_info_plus_macos
|
||||
import path_provider_macos
|
||||
@ -41,6 +42,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
FlutterWebRTCPlugin.register(with: registry.registrar(forPlugin: "FlutterWebRTCPlugin"))
|
||||
GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin"))
|
||||
JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin"))
|
||||
MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin"))
|
||||
FLTPackageInfoPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlugin"))
|
||||
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
|
14
pubspec.lock
14
pubspec.lock
@ -1012,6 +1012,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
mobile_scanner:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: mobile_scanner
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
move_to_background:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1320,13 +1327,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
qr_code_scanner:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: qr_code_scanner
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.7.0"
|
||||
qr_flutter:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -59,6 +59,7 @@ dependencies:
|
||||
lottie: ^1.2.2
|
||||
matrix: ^0.8.14
|
||||
matrix_link_text: ^1.0.2
|
||||
mobile_scanner: ^1.0.0
|
||||
open_noti_settings: ^0.4.0
|
||||
package_info_plus: ^1.3.0
|
||||
path_provider: ^2.0.9
|
||||
@ -66,7 +67,6 @@ dependencies:
|
||||
pin_code_text_field: ^1.8.0
|
||||
provider: ^6.0.2
|
||||
punycode: ^1.0.0
|
||||
qr_code_scanner: ^0.7.0
|
||||
qr_flutter: ^4.0.0
|
||||
receive_sharing_intent: ^1.4.5
|
||||
record: ^3.0.2
|
||||
|
Loading…
x
Reference in New Issue
Block a user