Flutter Image Picker Stuck On Camera - ios

I use the plugin https://pub.dev/packages/image_picker
image_picker: ^0.8.0+3
on android the code runs fine on some devices, but when installed on ios, but when taking pictures with the camera, the application is stuck on the camera display
i using i phone 5 and i phone 10, but both stuck on camera display,
Button "Retake" and "Use Photo" cant click
here is my code
final pickedFile = await picker.getImage(
maxWidth: 800,
imageQuality: 85,
source: ImageSource.camera,
);
if (pickedFile != null) {
dPrint('Original path: ${pickedFile.path}');
String dir = path.dirname(pickedFile.path);
var timeStamp = DateTime.now().millisecondsSinceEpoch;
var fileName = "IMG_" + timeStamp.toString() + ".jpg";
String newPath = path.join(dir, fileName);
File newFile = await File(pickedFile.path).copy(newPath);
if (newFile != null) {
print(newFile);
}
}
Flutter doctor result :
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.0, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-ID)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] Connected device (1 available)
! Doctor found issues in 1 category.
Flutter 2.0.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 60bd88df91 (3 months ago) • 2021-03-03 09:13:17 -0800
Engine • revision 40441def69
Tools • Dart 2.12.0

You need to tap on Use Photo to get the image captured

Related

flutter sdk 2.5.3 permission_handler(^8.2.5) status has wrong value

After upgrading flutter version from 2.2 to 2.5.3, permission_handler behaves abnormally.
PermissionStatus status = await Permission.photos.status;
print('## deny: ${status.isDenied}');
print('## grant: ${status.isGranted}');
print('## limit: ${status.isLimited}');
print('## permanently deny: ${status.isPermanentlyDenied}');
print('## restrict: ${status.isRestricted}');
if (!status.isGranted) {
await showDialog(
Even though access to all photos is allowed, the result is as follows.
flutter: ## deny: true
flutter: ## grant: false
flutter: ## limit: false
flutter: ## permanently deny: false
flutter: ## restrict: false
https://pub.dev/packages/permission_handler
I checked the above documentation but couldn't find a solution.
flutter doctor
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.3, on macOS 11.6 20G165 darwin-x64, locale ko-KR)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] Connected device (2 available)
! Doctor found issues in 1 category.

FlutterFire Firebase_ml_vision: PlatformException(Error 13, com.firebase.ml, Barcode engine is nil., null)

I've been using the 'firebase_ml_vision' package to scan Qr codes in an Image Stream provided by the 'camera' package. Everything was fine until the update that happened in Nov. 6. In Android, I can still scan qr codes without problems. But in iOS, i'm having the app is throwing the Exception: PlatformException(Error 13, com.firebase.ml, Barcode engine is nil., null)
I've updated my podfile with the line pod 'GoogleMLKit/BarcodeScanning', because the command 'flutter build ios' finished with an error when the Podfile had pod 'Firebase/MLVisionBarcodeModel' instead. I did because the pod update command explained that the package 'Firebase/MLVisionBarcodeModel' was deprecated, and thought it was the source of the problem.
Still the problem keeps happening.
Flutter doctor -v output:
[✓] Flutter (Channel stable, 1.22.4, on Mac OS X 10.15.6 19G73 darwin-x64, locale en-EC)
• Flutter version 1.22.4 at /Applications/flutter_sdk/jaime/flutter
• Framework revision 1aafb3a8b9 (3 weeks ago), 2020-11-13 09:59:28 -0800
• Engine revision 2c956a31c0
• Dart version 2.10.4
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/jvasquez/Library/Android/sdk
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.1, Build version 12A7403
• CocoaPods version 1.10.0
[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 46.0.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] VS Code (version 1.51.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.16.0
[!] Connected device
! No devices available
! Doctor found issues in 1 category.
This is the code I use to analyze the CameraImage:
static Future<List<Barcode>> detect({
#required CameraImage image,
// #required BarcodeDetector detector,
#required int imageRotation,
}) async {
var rp = List<Barcode>();
try {
BarcodeDetector detector = FirebaseVision.instance.barcodeDetector(
BarcodeDetectorOptions(
barcodeFormats: BarcodeFormat.qrCode,
)
);
var metadata = _buildMetaData(image, _rotationIntToImageRotation(imageRotation));
FirebaseVisionImage visionImage = FirebaseVisionImage.fromBytes(_concatenatePlanes(image.planes), metadata);
rp = await detector.detectInImage(visionImage);
} catch (ex) {
print("Ocurrió un error: $ex");
// UtilFunctions.escribirEnLog(
// mensaje: "$ex",
// nombreFuncion: "detect",
// tipo: 0,
// );
}
return rp;
}
static Uint8List _concatenatePlanes(List<Plane> planes) {
final WriteBuffer allBytes = WriteBuffer();
for (Plane plane in planes) {
allBytes.putUint8List(plane.bytes);
}
return allBytes.done().buffer.asUint8List();
}
The problem is, that firebase_ml_vision internally uses Firebase/MLVisionBarcodeModel and not GoogleMLKit/BarcodeScanning.
In the issue https://github.com/FirebaseExtended/flutterfire/issues/4625 another user forked the firebase_ml_vision package and adjusted it to work with GoogleMLKit/BarcodeScanning. There is also a PR for this form (https://github.com/FirebaseExtended/flutterfire/pull/5378).
It is important to mention that some functionality, especially cloud functionality, has been removed to make it work.
Therefore, this could break parts of your app where these features are missing and it is yet not a great solution.
To use the forked package include the following in your Pubspec.yaml
firebase_ml_vision:
git:
url: git://github.com/algirdasmac/flutterfire
path: packages/firebase_ml_vision

Flutter with firebase_messaging - how to custom message on permission dialog?

I'm using fcm and firebase_messaging to send push notification to flutter app, and want to custom permission message when executing FirebaseMessaging().requestNotificationPermissions for ios remote notification.
Now I have permission dialog below
How to custom '"" Would Like to Send You Notifications', 'Notifications may include alerts, sounds, and icon...', and 'Don't Allow/Allow'? Does anyone any idea?
and my code
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
await _firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(
sound: true, badge: true, alert: true));
await _firebaseMessaging.onIosSettingsRegistered.listen((settings) {
debugPrint('Settings registered: $settings');
});
Here's my flutter doctor -v result
[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.1 19B88, locale ja-JP)
• Flutter version 1.12.13+hotfix.5 at /usr/local/bin/flutter
• Framework revision 27321ebbad (6 weeks ago), 2019-12-10 18:15:01 -0800
• Engine revision 2994f7e1e6
• Dart version 2.7.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/shunmanabe/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.41.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.7.1
[✓] Connected device (1 available)
• iPhone 11 • 4B5E0CE0-8D25-49CC-BEBA-0BDE35991977 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)
• No issues found!
Thanks in advance!
first update to the latest firebase messaging dependency in your pubspec.yaml file
firebase_messaging: ^9.1.0
then create an instance of firebase messaging
final FirebaseMessaging firebaseMessaging = FirebaseMessaging.instance;
then request for the permission
Future initialize(context) async {
if (Platform.isIOS) {
firebaseMessaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
}
}
In my case i updated the firebase dependency firebase_messaging: ^10.0.2 and replace
_fcm.requestNotificationPermissions(const IosNotificationSettings())
to
_fcm.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
but we will have to change
_fcm.configure()
as well, change it with below code.
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
RemoteNotification _notification = message.notification;
AndroidNotification _android = message.notification?.android;
});
and problem solved.

mDns error on iOS - error 49 Can't assign requested address

I'm using the multicast_dns package for Flutter and get an exception on iOS.
It works as expected on Android. I have tested this with the code example provided with the package, see https://pub.dev/packages/multicast_dns
The error is:
OS Error: Can't assign requested address, errno = 49 in
_NativeSocket.joinMulticast. (socket_patch.dart)
I have tried various multicast addresses, the default 224.0.0.251, 230.180.0.1 and 239.0.180.1.
import 'package:multicast_dns/multicast_dns.dart';
Future<void> main() async {
const String name = '_dartobservatory._tcp.local';
final MDnsClient client = MDnsClient();
await client.start(mDnsAddress: InternetAddress('239.0.180.1'));
await for (PtrResourceRecord ptr in client
.lookup<PtrResourceRecord>(ResourceRecordQuery.serverPointer(name))) {
await for (SrvResourceRecord srv in client.lookup<SrvResourceRecord>(
ResourceRecordQuery.service(ptr.domainName))) {
final String bundleId =
ptr.domainName; //.substring(0, ptr.domainName.indexOf('#'));
print('Dart observatory instance found at '
'${srv.target}:${srv.port} for "$bundleId".');
}
}
client.stop();
print('Done.');
}
Flutter doctor:
mdnstest $ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.9.1+hotfix.4, on Mac OS X 10.14.5 18F203, locale
en)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
✗ Android licenses not accepted. To resolve this, run: flutter doctor
--android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
[✓] Android Studio (version 3.5)
[✓] Connected device (1 available)
! Doctor found issues in 1 category.

Ads are not showing on iOS devices

In flutter, we want to use AdMob.
We set as follows.
Because there may be relationships, we also write Firebase Analytics.
[pubspec.yaml]
dependencies:
flutter:
sdk: flutter
firebase_admob: ^0.5.7
firebase_analytics: ^1.0.3
[main.dart]
void main() {
// [Analytics]
FirebaseAnalytics().logAppOpen();
// [Initialize:AdMob]
FirebaseAdMob.instance.initialize(
appId: Platform.isAndroid
? 'ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx'
: 'ca-app-pub-yyyyyyyyyyyyyyyy~yyyyyyyyyy',
);
// [Create Banner Ad:AdMob]
createBannerAd()
..load()
..show(
anchorType: AnchorType.top,
);
runApp(MyApp());
}
final MobileAdTargetingInfo targetingInfo = new MobileAdTargetingInfo(
testDevices: Const.testDevices,
keywords: <String>[
'foo',
'bar',
],
birthday: new DateTime.now(),
childDirected: true,
gender: MobileAdGender.female,
);
// [Create Banner Ad:AdMob]
BannerAd createBannerAd() {
return new BannerAd(
adUnitId: Platform.isAndroid
? 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX'
: 'ca-app-pub-YYYYYYYYYYYYYYYY~YYYYYYYYYY',
size: AdSize.banner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("BannerAd event $event");
},
);
}
We download the Firebase configuration file and place it in the following.
In Xcode's Target Membership, we have confirmed that it is set correctly.
/android/app/google-services.json
/ios/Runner/GoogleService-Info.plist
It is displayed normally on Android device.
However, it is not displayed on the iOS device.
The following log was output.
2018-08-29 11:21:58.147849+0900 Runner[459:115739] FirebaseAdMobPlugin <warning> [FIRApp configure]
2018-08-29 11:21:58.157062+0900 Runner[459:115880] 5.5.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more:
[abridgement]
2018-08-29 11:21:59.755279+0900 Runner[459:115739] FirebaseAdMobPlugin <warning> adView:didFailToReceiveAdWithError: Request Error: No ad to show. (MobileAd <FLTBannerAd: 0x113ef81b0> PENDING mobileAdId:ZZZZZZZZZ for: <GADBannerView: 0x113efa7b0; frame = (0 0; 320 50); clipsToBounds = YES; layer = <CALayer: 0x113efac40>>)
2018-08-29 11:21:59.757247+0900 Runner[459:115885] flutter: BannerAd event MobileAdEvent.failedToLoad
How should we implement [FIRApp configure]; in the flutter?
Is it unnecessary? We could not find it in the sample code.
Is our setting correct?
If we wait for a few more days, will mobileAdId not be pending?
$ flutter doctor -v
[✓] Flutter (Channel dev, v0.7.2, on Mac OS X 10.13.6 17G65, locale ja)
• Flutter version 0.7.2 at /Applications/flutter
• Framework revision f8a2fc7c28 (4 days ago), 2018-08-27 20:58:30 +0200
• Engine revision af42b6dc95
• Dart version 2.1.0-dev.1.0.flutter-ccb16f7282
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
• Android SDK at /Users/xxxxx/src/android-sdks
• Android NDK at /Users/xxxxx/src/android-sdks/ndk-bundle
• Platform android-27, build-tools 27.0.3
• ANDROID_HOME = /Users/xxxxx/src/android-sdks
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 9.4.1, Build version 9F2000
• ios-deploy 1.9.2
• CocoaPods version 1.5.3
[✓] Android Studio (version 3.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 27.1.1
• Dart plugin version 173.4700
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
[✓] VS Code (version 1.25.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 2.17.1
[✓] Connected devices (1 available)
• iPhone 6 Plus • XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX • ios • iOS 11.4.1
• No issues found!
In parallel with this question, we also contact AdMob.
Ads will not be shown using the following app ID and ad unit ID.
ca-app-pub-3940256099942544~1458002511
ca-app-pub-3940256099942544/2934735716
We tried several terminals.
[OK] ASUS Z017DA (Android)
[OK] iPad mini
[OK] iPhone 4s
[NG] iPhone 6 Plus
[NG] iPhone SE
We tried various changes but they were ineffective. However, today "No ad to show" suddenly ceased to occur. But the ad was not displayed yet.
We thought that ads might be displayed outside the screen. When we made the following settings, the ad was displayed in the place we expected.
_bannerAd
  ..load()
  ..show(
    anchorType: AnchorType.top,
    anchorOffset: 50.0,
  );
However, in the terminal normally displayed before the change, the ad was displayed shifted downward. We could not adopt this method because we can not try all the terminals.
Next, we placed the ad under the screen.
_bannerAd
  ..load()
  ..show(
    anchorType: AnchorType.bottom,
  );
In this case, we were able to confirm that ad is displayed normally on all terminals. We wanted to place the ad on top but we gave it up.
AnchorType.top may be incorrect in some cases.
-> Privacy then
-> Adverting then
-> Limit Ad Tracking Admob is now displayed when repeating on and off.
Perhaps it is bad that DeviceID is in the same state?

Resources