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.
Related
I am new to flutter and recently tried to develop a test app for learning sake with latest version Flutter 2.5. By looking at some tutorial online, I have added flutter_native_splash: ^1.2.3 package for splash screen. And works fine.
However, when I launch app for the first time, it shows following debug message
W/FlutterActivityAndFragmentDelegate(18569): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.
After visiting the above link, I am not able to understand much what is supposed to be done.
Code in pubspec.yaml
flutter_native_splash:
color: "#FFFFFF"
color_dark: "#000000"
image: assets/images/splash_720.png
android: true
ios: true
android12: true
Also, compileSdkVersion and targetSdkVersion is set to 31 in build.gradle
Please help. Thanks in advance.
To avoid that warning you just need to remove that API usage from your project.
Remove these lines of code from the AndroidManifest.xml file.
Previously, Android Flutter apps would either set io.flutter.embedding.android.SplashScreenDrawable in their application manifest, or implement provideSplashScreen within their Flutter Activity. This would be shown momentarily in between the time after the Android launch screen is shown and when Flutter has drawn the first frame. This is no longer needed and is deprecated – Flutter now automatically keeps the Android launch screen displayed until Flutter has drawn the first frame. Developers should instead remove the usage of these APIs. - source
UPDATE (FLUTTER 2.8.0)
As per the flutter 2.8.0 update, The newly created project doesn't have this warning.
They removed unused API from Androidmanifest.yml but still have belove mentioned code.
Remove the below lines from the android manifest file. It's no longer used
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"/>
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"/>
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>
Info:
Package: image_picker plugin for flutter, version 0.6.3+1
Android build only, no IOS
Problem:
This is my method to pick an image:
Future<void> pickImage(ImageSource source) async {
File selected = await ImagePicker.pickImage(source: source);
print(selected?.path);
imageFilePath = selected?.path ?? imageFilePath;
}
=> When using ImageSource.gallery, when choosing a picture which is not in cache, 'selected.path' prints null. When selecting a picture which is in cache, it does retrieve it, 'selected.path' prints:
/data/user/0/be.etnic.parrainage_mcf/cache/image_picker2517179621202627006.jpg
Anyone knows what causes this problem and how I can solve it?
Sidenotes:
I can also pick an image by making a picture directly with ImageSource.camera, this doesn't give me any problems.
I'm not 100% sure that the selected pictures that return null
are not in cache, but the pictures that do return correctly from
choosing from the ImageSource.gallery all come from that
cache-folder
I don't have any permissions set in my AndroidManifest.xml
(other than Internet permission)
Based on this link https://github.com/flutter/flutter/issues/41459#issuecomment-563986851, following should solve the problem:
android:requestLegacyExternalStorage="true"
I have imported
import 'package:flutter/services.dart';
and then called
HapticFeedback.lightImpact();
nothing happens. What do I need to do to get it working?
I am testing with the latest Flutter version 1.6.6 on a Galaxy S8 running Android 9.0
Please make sure that Vibration feedback is enabled on the android device, and make sure to add
<uses-permission android:name="android.permission.VIBRATE" />
to the AndroidManifest.xml.
See more info here: https://github.com/flutter/flutter/issues/33750
import 'package:flutter/services.dart';
import the services package
then inside onTap method
onTap: () {
Clipboard.setData(ClipboardData(text: data));
HapticFeedback.heavyImpact();
}
it worked for me.
Please also check whether, Vibration feedback setting was enabled on the device or not . I faced same issue but later found out that Haptic Feedback vibration was off on my device (I was testing it in Android 9) so, make sure to enable it.
To enable it,
Go to settings>sound&vibration>touch vibration
Try using this for Android:
Feedback.forTap(context);
More info: https://api.flutter.dev/flutter/material/Feedback-class.html
This is helped me
First Go to AndroidManifest and add
<uses-permission android:name="android.permission.VIBRATE" />
If the Flutter app is running stop it and run it again.
Then use this code
import 'package:flutter/services.dart';
And in Ontap or OnPressed Method
Clipboard.setData(ClipboardData());
HapticFeedback.heavyImpact();
That's all
Reading the function description it says:
"On Android, this uses HapticFeedbackConstants.KEYBOARD_TAP."
If the vibrations for the keyboard or 'haptic feedback for tap' are turned off (in the phone's settings), calling HapticFeedback.mediumImpact(); will not have an effect.
To fix the problem one would have to turn on Touch vibration in the phone's settings.
If only activating touch vibration on phone doesn't solve the issue , try switching between Vibrate on tap modes.Default setting is Off.
Vibrate on tap (Settings -Off(default),Ligh,Medium,Strong)
I have noticed this problem with flutter apps, when I open a flutter app from cold boot, I see a black screen popping before the actual app is loaded. I have seen the problem with the Newsvoice production app and as well as with a test app I installed.
Check the video here: https://www.youtube.com/watch?v=zszud6UWzps
Is it a bug in the Flutter SDK?
This issue was fixed recently. If you are using a version of Flutter that has this engine fix, you won't see the black frame. (The fix should be on the Flutter master branch by now, but not the alpha branch.)
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/my_splash"
/>
AndroidManifest.xml check the FlutterActivity and add this code
It's not issue, this for hot reload. Don't worry about that. When you run with release, you can't see this.
if you want to be sure try ->
flutter run --release
It's not a bug. That's the way it behaves normally. You can replace the loading black screen with an image:
In AndroidManifest.xml, here is where you can change your splash image.
<meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background" />
Find the files:
android\app\src\main\res\drawable\launch_background.xml
android\app\src\main\res\drawable-v21\launch_background.xml
Change the files to add your own custom image:
<item>
<bitmap android:gravity="center" android:src="#drawable/splash_image" />
</item>
Your splash image should be stored in the drawable folders:
android\app\src\main\res\drawable\splash_image.png
app\src\main\res\drawable-v21\splash_image.png
I can solve this issue, after removing FutureBuilder when using Firebase. just initialize Firebase app on main() like this
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
instead of using FutureBuilder on your build method
The black screen is something which comes for a variety of reasons is what I have gathered from looking at different responses on the net. In my case I realized on thing, that my Firebase.initializeApp() was returning an error in the snapshot of my FutureBuilder due to which no widgets were being rendered. I tried everything to no avail. Finally I moved my project to a completely new folder as described here
and then my black screen issue got resolved.