Flutter app shows a black screen before loading the app - flutter

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.

Related

Flutter (2.5) - A splash screen was provided to Flutter, but this is deprecated

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"/>

Flutter splash screen not showing

I'am trying to add a splash screen on my application , i'am pretty sure i made all the steps correctly
I've added my picture on launch_background.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#android:color/black"/>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/1-ZID-SplashScreen" />
</item>
</layer-list>
And i have added the path of the picture which is located on drawable folder on pubsec.yaml
flutter:
assets:
- assets/images/
- assets/google_fonts/
- android/app/src/main/res/drawable/
But still the splash screen stills white, help me resolve this please ^^
Thanks.
You can use flutter_native_splash it will help you achieve what you want
You can add a native splash screen to your app in 02 ways.
Using flutter package.
This is the easiest way to add a splash screen for your flutter app. (You don't need to have prior Native android & ios development knowledge).
Link to package:- package
This video shows that how to use this package:- video tutorial
Without using flutter package (Native way)
For this method, you needed to have prior native android & ios development experience.
If you had native development experience, you can use the below links to see the steps.
Link
As I know, the ressource name (in your case "android:src="#drawable/1-ZID-SplashScreen") should start with a letter not a number (google the android ressources naming convention for more information).

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.

Black screen on startup after updating flutter

I recently updated the flutter. For running flutter project I am using android via usb. And after updating every project on startup shows black screen. Previous version worked fine. I tried to change launch splash screen(drawable/launch_background.xml) in android to white but black screen shows after splash screen.
This is the simple code I am trying to run
void main()=> runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context){
return MaterialApp(
home:MyHomePage(),
);
}
}
So how can I remove black screen on startup?
The black screen like here.
As I said black screen shows after updating flutter to a new version. And I downgraded the flutter version to old and black screen disappeared.
I had the same problem when I switched to beta channel of flutter.
I noticed there is another launch_background.xml file in drawable-v21 folder.
so I copied the content of launch_background.xml in drawable folder to launch_background.xml in drawable-v21 and it worked.
If you see the black window background of the activity showing until Flutter renders its first frame you should add this on your AndroidManifest, between < activity> ... < /activity>
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"
/>
I had a black screen after splash Screen on iOS. I had a line like this in the Info.plist file in Runner:
<string>LaunchScreen.storyboard</string>
I changed this line like this:
<string>LaunchScreen</string>
and the black screen went away
The solution to this problem is quite easy. I have been facing this problem since months and now I came up with a solution.
Run this command in terminal
flutter config --no-enable-android-embedding-v2
And from next project you won't face such problem. But make sure that 'enable-android-embedding-v2' is set to 'false' by running command
flutter config
on terminal.
Thank You!
I had the same issue with my flutter project. It has a simple fix in the AndroidManifest.xml. Make sure that
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"
/>
Is above
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"
/>
In the AndroidManifest.xml

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