From 6d57c3af346189fd685f14f75bf5211abed48b17 Mon Sep 17 00:00:00 2001 From: Adam Velebil Date: Tue, 26 Apr 2022 16:05:59 +0200 Subject: [PATCH] YADESK-663 open QR Scanner directly on Android --- lib/oath/views/add_account_page.dart | 17 ++++++++++++++++- lib/oath/views/oath_screen.dart | 7 ++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/oath/views/add_account_page.dart b/lib/oath/views/add_account_page.dart index 5575f031..84fb5e38 100755 --- a/lib/oath/views/add_account_page.dart +++ b/lib/oath/views/add_account_page.dart @@ -24,7 +24,10 @@ enum _QrScanState { none, scanning, success, failed } class OathAddAccountPage extends ConsumerStatefulWidget { final DevicePath devicePath; - const OathAddAccountPage(this.devicePath, {Key? key}) : super(key: key); + final bool openQrScanner; + const OathAddAccountPage(this.devicePath, + {Key? key, required this.openQrScanner}) + : super(key: key); @override ConsumerState createState() => @@ -98,6 +101,18 @@ class _OathAddAccountPageState extends ConsumerState { } } + @override + void initState() { + super.initState(); + + final qrScanner = ref.read(qrScannerProvider); + if (qrScanner != null && widget.openQrScanner) { + WidgetsBinding.instance.addPostFrameCallback((_) { + _scanQrCode(qrScanner); + }); + } + } + @override Widget build(BuildContext context) { // If current device changes, we need to pop back to the main Page. diff --git a/lib/oath/views/oath_screen.dart b/lib/oath/views/oath_screen.dart index 79efe190..dfad722f 100755 --- a/lib/oath/views/oath_screen.dart +++ b/lib/oath/views/oath_screen.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -126,7 +128,10 @@ class _UnlockedView extends ConsumerWidget { action: (context) { showDialog( context: context, - builder: (context) => OathAddAccountPage(devicePath), + builder: (context) => OathAddAccountPage( + devicePath, + openQrScanner: Platform.isAndroid, + ), ); }, ),