Navaron Bracke

update code sample to fix a potential bug; update changelog

@@ -2,6 +2,10 @@ @@ -2,6 +2,10 @@
2 2
3 Bugs fixed: 3 Bugs fixed:
4 * Fixed a crash when the controller is disposed while it is still starting. [#1036](https://github.com/juliansteenbakker/mobile_scanner/pull/1036) (thanks @EArminjon !) 4 * Fixed a crash when the controller is disposed while it is still starting. [#1036](https://github.com/juliansteenbakker/mobile_scanner/pull/1036) (thanks @EArminjon !)
  5 +* Fixed an issue that causes the initial torch state to be out of sync.
  6 +
  7 +Improvements:
  8 +* Updated the lifeycle code sample to handle not-initialized controllers.
5 9
6 ## 5.0.1 10 ## 5.0.1
7 11
@@ -103,7 +103,11 @@ class MyState extends State<MyStatefulWidget> with WidgetsBindingObserver { @@ -103,7 +103,11 @@ class MyState extends State<MyStatefulWidget> with WidgetsBindingObserver {
103 103
104 @override 104 @override
105 void didChangeAppLifecycleState(AppLifecycleState state) { 105 void didChangeAppLifecycleState(AppLifecycleState state) {
106 - super.didChangeAppLifecycleState(state); 106 + // If the controller is not ready, do not try to start or stop it.
  107 + // Permission dialogs can trigger lifecycle changes before the controller is ready.
  108 + if (!controller.value.isInitialized) {
  109 + return;
  110 + }
107 111
108 switch (state) { 112 switch (state) {
109 case AppLifecycleState.detached: 113 case AppLifecycleState.detached:
@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3 <plist version="1.0"> 3 <plist version="1.0">
4 <dict> 4 <dict>
  5 + <key>CADisableMinimumFrameDurationOnPhone</key>
  6 + <true/>
5 <key>CFBundleDevelopmentRegion</key> 7 <key>CFBundleDevelopmentRegion</key>
6 <string>$(DEVELOPMENT_LANGUAGE)</string> 8 <string>$(DEVELOPMENT_LANGUAGE)</string>
7 <key>CFBundleDisplayName</key> 9 <key>CFBundleDisplayName</key>
@@ -28,6 +30,8 @@ @@ -28,6 +30,8 @@
28 <string>This app needs camera access to scan QR codes</string> 30 <string>This app needs camera access to scan QR codes</string>
29 <key>NSPhotoLibraryUsageDescription</key> 31 <key>NSPhotoLibraryUsageDescription</key>
30 <string>This app needs photos access to get QR code from photo library</string> 32 <string>This app needs photos access to get QR code from photo library</string>
  33 + <key>UIApplicationSupportsIndirectInputEvents</key>
  34 + <true/>
31 <key>UILaunchStoryboardName</key> 35 <key>UILaunchStoryboardName</key>
32 <string>LaunchScreen</string> 36 <string>LaunchScreen</string>
33 <key>UIMainStoryboardFile</key> 37 <key>UIMainStoryboardFile</key>
@@ -47,9 +51,5 @@ @@ -47,9 +51,5 @@
47 </array> 51 </array>
48 <key>UIViewControllerBasedStatusBarAppearance</key> 52 <key>UIViewControllerBasedStatusBarAppearance</key>
49 <false/> 53 <false/>
50 - <key>CADisableMinimumFrameDurationOnPhone</key>  
51 - <true/>  
52 - <key>UIApplicationSupportsIndirectInputEvents</key>  
53 - <true/>  
54 </dict> 54 </dict>
55 </plist> 55 </plist>
@@ -63,7 +63,9 @@ class _BarcodeScannerWithControllerState @@ -63,7 +63,9 @@ class _BarcodeScannerWithControllerState
63 63
64 @override 64 @override
65 void didChangeAppLifecycleState(AppLifecycleState state) { 65 void didChangeAppLifecycleState(AppLifecycleState state) {
66 - super.didChangeAppLifecycleState(state); 66 + if (!controller.value.isInitialized) {
  67 + return;
  68 + }
67 69
68 switch (state) { 70 switch (state) {
69 case AppLifecycleState.detached: 71 case AppLifecycleState.detached:
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 # 4 #
5 Pod::Spec.new do |s| 5 Pod::Spec.new do |s|
6 s.name = 'mobile_scanner' 6 s.name = 'mobile_scanner'
7 - s.version = '5.0.0' 7 + s.version = '5.0.2'
8 s.summary = 'An universal scanner for Flutter based on MLKit.' 8 s.summary = 'An universal scanner for Flutter based on MLKit.'
9 s.description = <<-DESC 9 s.description = <<-DESC
10 An universal scanner for Flutter based on MLKit. 10 An universal scanner for Flutter based on MLKit.
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 # 4 #
5 Pod::Spec.new do |s| 5 Pod::Spec.new do |s|
6 s.name = 'mobile_scanner' 6 s.name = 'mobile_scanner'
7 - s.version = '5.0.0' 7 + s.version = '5.0.2'
8 s.summary = 'An universal scanner for Flutter based on MLKit.' 8 s.summary = 'An universal scanner for Flutter based on MLKit.'
9 s.description = <<-DESC 9 s.description = <<-DESC
10 An universal scanner for Flutter based on MLKit. 10 An universal scanner for Flutter based on MLKit.