From 5ebcfac0f01e064f383926595583d6ee5391d6dc Mon Sep 17 00:00:00 2001 From: r4khul Date: Thu, 5 Feb 2026 01:34:39 +0530 Subject: [PATCH 1/2] Improve permission denied error handling by providing direct access to app settings --- lib/qr_code_screen.dart | 31 +++++++++++++++++++++++++++++++ pubspec.lock | 8 ++++++++ pubspec.yaml | 1 + 3 files changed, 40 insertions(+) diff --git a/lib/qr_code_screen.dart b/lib/qr_code_screen.dart index 05f9295..31f7fb8 100644 --- a/lib/qr_code_screen.dart +++ b/lib/qr_code_screen.dart @@ -1,3 +1,4 @@ +import 'package:app_settings/app_settings.dart'; import 'package:flutter/material.dart'; import 'package:mobile_scanner/mobile_scanner.dart'; @@ -66,6 +67,36 @@ class _QrCodeScreenState extends State { controller: _controller, fit: BoxFit.cover, onDetect: _onDetect, + errorBuilder: (context, error) { + return Center( + child: Padding( + padding: const EdgeInsets.all(24.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Icon(Icons.videocam_off_outlined, size: 64), + const SizedBox(height: 16), + Text( + error.errorCode == MobileScannerErrorCode.permissionDenied + ? "Camera Permission Has Been Denied" + : error.errorDetails?.message ?? "Camera Error", + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.bodyLarge, + ), + const SizedBox(height: 24), + FilledButton.icon( + onPressed: + () => AppSettings.openAppSettings( + type: AppSettingsType.settings, + ), + icon: const Icon(Icons.settings), + label: Text("Open Settings"), + ), + ], + ), + ), + ); + }, ), ); } diff --git a/pubspec.lock b/pubspec.lock index 4ba9485..f750490 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -41,6 +41,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.4" + app_settings: + dependency: "direct main" + description: + name: app_settings + sha256: "64d50e666fd96ae90301bf71205f05019286f940ad6f5fed3d1be19c6af7546a" + url: "https://pub.dev" + source: hosted + version: "7.0.0" archive: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 42d28b8..1dbb912 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,6 +25,7 @@ dependencies: mobile_scanner: ^7.1.4 flutter_secure_storage: ^10.0.0 app_links: ^7.0.0 + app_settings: ^7.0.0 dev_dependencies: flutter_test: From 6d0ed737dda9f57850ece294b53691d26fcbd0f0 Mon Sep 17 00:00:00 2001 From: r4khul Date: Tue, 10 Feb 2026 23:45:06 +0530 Subject: [PATCH 2/2] Simplfy errorBuilder widget with pre-existing localized strings --- lib/qr_code_screen.dart | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/qr_code_screen.dart b/lib/qr_code_screen.dart index 31f7fb8..b8ae4b0 100644 --- a/lib/qr_code_screen.dart +++ b/lib/qr_code_screen.dart @@ -56,8 +56,8 @@ class _QrCodeScreenState extends State { : Icons.flash_off, ), onPressed: state.torchState == TorchState.unavailable - ? null - : () => _controller.toggleTorch(), + ? null + : () => _controller.toggleTorch(), ); }, ), @@ -74,23 +74,15 @@ class _QrCodeScreenState extends State { child: Column( mainAxisSize: MainAxisSize.min, children: [ - const Icon(Icons.videocam_off_outlined, size: 64), - const SizedBox(height: 16), - Text( - error.errorCode == MobileScannerErrorCode.permissionDenied - ? "Camera Permission Has Been Denied" - : error.errorDetails?.message ?? "Camera Error", - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.bodyLarge, - ), - const SizedBox(height: 24), - FilledButton.icon( + Icon(Icons.videocam_off_outlined, size: 120), + Text(AppLocalizations.of(context)!.disabledValue), + SizedBox(height: 24,), + FilledButton.tonal( onPressed: () => AppSettings.openAppSettings( type: AppSettingsType.settings, ), - icon: const Icon(Icons.settings), - label: Text("Open Settings"), + child: Text(AppLocalizations.of(context)!.settingsTitle), ), ], ),