@@ -26,6 +26,8 @@ import 'platform/platform_info_stub.dart'
2626typedef QRViewCreatedCallback = void Function (QRViewController );
2727typedef PermissionSetCallback = void Function (QRViewController , bool );
2828
29+ const _defaultIOSMajorVersionOnUnknown = 18 ;
30+
2931/// The [QRView] is the view where the camera
3032/// and the barcode scanner gets displayed.
3133class QRView extends StatefulWidget {
@@ -308,17 +310,24 @@ class QRViewController {
308310 try {
309311 final osVersionSplit = osVersion.split (' ' );
310312
311- final iOSVersion =
312- osVersionSplit.length > 1 ? osVersionSplit[1 ] : 'Unknown' ;
313- final iOSVersionDouble = double .tryParse (iOSVersion) ?? 0 ;
313+ // iOS version is sth like 26.0 or 26.0.1, etc.
314+ // We cannot assume it would parse as a double, so we need to handle that.
315+ final iOSVersion = osVersionSplit.length > 1
316+ ? osVersionSplit[1 ]
317+ : "$_defaultIOSMajorVersionOnUnknown .0" ;
318+
319+ final iOSMajorVersion = int .tryParse (
320+ iOSVersion.split ('.' ).firstOrNull ??
321+ '$_defaultIOSMajorVersionOnUnknown ' ) ??
322+ _defaultIOSMajorVersionOnUnknown;
323+ final isAtLeastIOS18 = iOSMajorVersion >= 18 ;
314324
315- // print('iOSVersionDouble $iOSVersionDouble');
316- if (iOSVersionDouble < 18.0 ) {
317- // Don't call stopCamera on iOS 18 or higher
325+ if (isAtLeastIOS18) {
326+ // Don't call stopCamera on iOS 18+
318327 // -- it causes UI to hang for a few seconds, especially on iOS 26+
319- await _channel.invokeMethod ('stopCamera' );
320- } else {
321328 await _channel.invokeMethod ('pauseCamera' );
329+ } else {
330+ await _channel.invokeMethod ('stopCamera' );
322331 }
323332 } on PlatformException catch (e) {
324333 throw CameraException (e.code, e.message);
0 commit comments