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