iOS simulator crashes when using image_picker - flutter

ElevatedButton(
onPressed: () async {
final XFile? image =
await picker.pickImage(source: ImageSource.gallery);
},
child: Text('Add photo'),
),
As described in the image_picker example this should work when the button is clicked but the app just crashes without any debug info.

After reading the image_picker docs it says that when using the iOS 14+ simulator. However they fail to mention that the app will also crash. In order for you to use this in the simulator you need give access to the image gallery to add this to your info.plist:
<key>NSPhotoLibraryUsageDescription</key>
<string>To chose a picture from the gallery</string>

From the Image Picker Docs:
Add the following keys to your Info.plist file, located in /ios/Runner/Info.plist:
NSPhotoLibraryUsageDescription- describe why your app needs permission for the photo library. This is called Privacy - Photo Library Usage Description in the visual editor.
NSCameraUsageDescription - describe why your app needs access to the camera. This is called Privacy - Camera Usage Description in the visual editor.
NSMicrophoneUsageDescription - describe why your app needs access to the microphone, if you intend to record videos. This is called Privacy - Microphone Usage Description in the visual editor.
If using Android Studio/ VS Code - goto ios/Runner/info.plist and add the following lines.
Note: You can add custom strings.
<key>NSCameraUsageDescription</key>
<string> App wants to access your camera</string>
<key>NSMicrophoneUsageDescription</key>
<string> App wants to access your gallery</string>
<key>NSPhotoLibraryUsageDescription</key>
<string> App wants to access your microphone</string>

Related

How can I change the name and the logo of google_sign_in with flutter?

I'm using google_sign_in + firebase to authenticate users via their google accounts in my flutter application.
I don't want my users to see the panel like the image below:
(It has the flutter logo and my project name! But I want to put the app logo and a customized name instead.)
Image:
Based on the provided image in your question there is no way to edit the icon and name of the application manually or by code in the mentioned screenshot, the only way is to change the entire project icon and project name which is guided as follows.
To change project name on Android
Open AndroidManifest.xml (located at android/app/src/main)
<application
android:label="App Name" ...> // Your app name here
To change project name on iOS
Open info.plist (located at ios/Runner)
<key>CFBundleName</key>
<string>App Name</string> // Your app name here
Don't forget to run
flutter clean
To change the project icon use the following flutter plugin or watch this youtube video
flutter_launcher_icons

image_picker: ^0.7.2+1 makes the app crash

i am using image_picker: ^0.7.2+1 here in my app
i am using this code for opening the camera
File _image;
final picker = ImagePicker();
Future getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.camera);
setState(() {
if (pickedFile != null) {
_image = File(pickedFile.path);
} else {
print('No image selected.');
}
});
}
also Added these Permissions in android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.INTERNET"
after using above package when my camera is opening immediately the app crashes and in terminal there is no error message it just says device disconnected. (by app crash i mean app restarts (from splash screen )automatically and captured image is also lost)
this above app crashing issue comes only in android 10 or above android version also in android 10 or above (android 11) also this packages does not asks for the permission of camera in android 10 or 11 which i guess can be the actual problem behind this issue
while i use android 8 or device with android version less then android 10 the image_picker: ^0.7.2+1 here works totally fine with same above given code (no changes are made in code just changed the device from android 11 to android 8) the app asks for permission as expected and then camera opens and successfully pic is captured and hence everything works fine nut same thing fails in android 10 or android 11
note : i also tried using permission_handler plugin with image_picker but it also didn't worked for me
can anyone please help me to fix this issue
also if some one know any substitute code or package for image_picker can please tell me.. i just want to take pic from from camera in flutter
I too went through all of this, setting up permission handling, doing the cache fix, and a few other bits I found online, and after a week could not solve it. Image_picker still crashed my app as soon as I took the shot. My solution in the end was to use camera_camera 2.0.1. It is a terrible library name, and it doesn't include compression, but the camera interface is nicer, and it works perfectly out of the box.
import 'package:camera_camera/camera_camera.dart';
onPressed: (){
Navigator.push( context, MaterialPageRoute(
builder: (_) => CameraCamera(
onFile: (file) {
// Do what you like with File file
// I convert to base64 ready to upload
Navigator.pop(context);
},
)))
},
Add android:requestLegacyExternalStorage="true" as an attribute to the <application> tag in AndroidManifest.xml. The attribute is false by default on apps targeting Android Q.
///// SOLVED /////
All you have to do to fix this is add these 6 lines to ios/Runner/Info.plist
<key>NSPhotoLibraryUsageDescription</key>
<string>Allow access to photo library</string>
<key>NSCameraUsageDescription</key>
<string>Allow access to camera to capture photos</string>
<key>NSMicrophoneUsageDescription</key>
<string>Allow access to microphone</string>
I had the same problem on several devices.
And since I used android:launchMode="singleTask" in AndroidManifest.xml everything works fine for me..
After stuck of 2 weeks finding solutions all round, I found my solution to give profile access to my users.
The solution is I used two alternative packages that work well.
For Getting Image Type
file_picker 5.2.2
For Getting Camera Image
camera 0.10.0+4
Now,it is working very well.
Also,we need to give kinda to Flutter as it is trying its best though having platform issue in some cases.

Ionic Capacitor: How to restrict Gallery from Camera options?

for an app that I'm building, I'm using Capacitor's Camera plugin. When I click the button that launches the camera, it's asking me to first choose between Gallery and Camera.
I'd like to turn the "Pick from Gallery" feature off.
Is there any solution for this?
By default the Camera plugin prompts, but you can select Camera or Gallery by passing the source attribute
// The source to get the photo from. By default this prompts the user to select either the photo album or take a photo. Default: CameraSource.Prompt
source ?: CameraSource;
Full example:
const image = await Camera.getPhoto({
quality: 90,
resultType: CameraResultType.Uri,
source: CameraSource.Camera
});

Flutter show app icon badge on push notification

I'm looking for a way to show an app icon badge when a user receives a push notification.
I'm using the Firebase_messaging plugin for flutter for the handling of the push notifications and flutter_app_badger for the app icon badges.
But I want to combine the two so that the number is set on the icon without opening the app. Is it possible to make this happen? Or am I overlooking something obvious from the firebase_messaging plugin?
Sorry for the horrible explanation. I hope someone can help me with this issue.
App icon badge depends on the Application Launcher
Some of the Android Application Launcher includes this functionality by default, You can check this on Settings->Apps->Notification
Attached image
FYI
How to show notification count on app icon like Facebook?
How does Facebook add badge numbers on app icon in Android?
adding notification badge on app icon in android
My suspicion is that you have an icon that isn't compatible with the icon guidelines in your device. I suggest trying https://pub.dev/packages/flutter_launcher_icons to make icons for your device.
I think you try to create stream when run app to real time listen doc changes in Firestore. Read here How to listen for document changes in Cloud Firestore using Flutter?
And the icon can be update in background but without opening app is impossible I think.
I don't have a direct answer because I haven't encountered this issue before, but this might fix your problem
Ensure that you have defined the icon for your application properly - for flutter, here are the steps you should have:
Import the package into your pubsec.yaml file - it should be called flutter_launcher_icons: "^0.8.0" and imported under the dev-dependencies section of the pubspec.yaml file.
After the dev-dependencies section, add a new section for flutter icons as so:
flutter_icons:
ios: true
android: true
image_path_ios: "{Icon File Path}"
image_path_android: "{Icon File Path}"
Hopefully this helps, and good luck with fixing your issue!
Using https://pub.dev/packages/firebase_messaging for notifications ,
for Android Background notifications you can add this in your AndroidManifest.xml file in your application tag. And make sure you have androidlogo.png (this is example name) present in your drawable folder.
<application>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/androidlogo" />
</application>
In case of foreground notifications, you must be using Flutter Local Notifications, so you can provide the same while initializing like
var initializationSettingsAndroid = new AndroidInitializationSettings('androidlogo');
flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: onNotificationClicked);
And for application icon you can use this library https://pub.dev/packages/flutter_launcher_icons which is also suggested by answers above.
In case of iOS, your launcher icon will your notification icon.
And for display of badge icon you can use https://pub.dev/packages/flutter_app_badger. (For supported phones).
So using all this you will get both app icon with badge and notification icon as your app icon (or specified by you).
You can control the badge count from the notification payload.
If you send a notification manually from Firebase Console, you can set the badge count on Additional options step:
If you send it programmatically, add this payload (iOS example):
{"aps":{"alert":"Enter your message","badge":1,"sound":"default"}}
For more payload options, check out FCM documentation

Display my app in the UIActionSheet of the default Photos app in iPhone

My app is registered for certain file types, images + pdf etc, following the guidelines
provided by Apple. My app does show up("open in" option) when pdf files are encountered
in mobile-safari, but it is not the case with image files. In the default "Photos"
app provided by apple, the "open in" option does not show up. Probably this is because
it is implemented without using the document interaction controller. But is there any
way to make my app appear in the UIActionSheet button, which appears at the bottom left
corner ?
I do not want to use the UIImagePickerController for choosing the saved images.
the only thing you can do is add this key-value pair to your info.plist file. iPhone saves pictures in ".JPG", so that's what you should put as the file type.
(if it doesn't appear in Photos action sheet, that means that Apple doesn't want it to appear. You'll just have to hope that some day...)
p.s. more information and detailed instructions here:
Registering the File Types Your App Supports