jonbhanson / flutter_native_splash

Automatically generates native code for adding splash screens in Android and iOS. Customize with specific platform, background color and splash image.
https://pub.dev/packages/flutter_native_splash
MIT License
1.3k stars 202 forks source link

app keeps on showing blue splash screen instead of logo. #505

Closed AbdulHaseeeb closed 1 year ago

AbdulHaseeeb commented 1 year ago

pubspec.yaml

name: bitbot
description: A new Flutter project.

publish_to: 'none'

version: 1.0.0+1

environment:
  sdk: '>=2.18.2 <3.0.0'

dependencies:
  build_runner: ^2.3.3
  carousel_slider: ^4.2.1
  cloud_firestore: ^4.3.1
  connectivity_plus: ^3.0.2
  cupertino_icons: ^1.0.2
  dropdown_button2: ^1.9.2
  email_validator: ^2.1.17
  firebase_auth: ^4.2.5
  firebase_core: ^2.4.1
  flutter:
    sdk: flutter
  flutter_launcher_icons: ^0.11.0
  flutter_riverpod: ^2.1.3
  flutter_spinkit: ^5.1.0
  flutter_svg: ^1.1.6
  flutter_tts: ^3.6.3
  go_router: ^6.0.1
  google_fonts: ^3.0.1
  http: ^0.13.5
  isar: ^3.0.5
  isar_flutter_libs: ^3.0.5
  isar_generator: ^3.0.5
  path_provider: ^2.0.11
  salomon_bottom_bar: ^3.3.1
  string_validator: ^0.3.0
  flutter_native_splash: ^2.2.16

dev_dependencies:
  flutter_lints: ^2.0.0
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
  assets:
    - assets/
    - assets/images/
    - assets/images/homepagecarouselimages/
    - assets/images/testimonials/profile/
    - assets/avatars/
    - assets/icons/
    - assets/logo/

flutter_native_splash:
  color: "#ffffff"
  image: assets/logo/botlogo.png

# this is for the launcher icon 
flutter_icons:
  android: true
  image_path: "assets/logo/botlogo.png"
  min_sdk_android: 21 # android min sdk min:16, default 21

main

main() async {
  //making sure flutter widgets are initialized
  WidgetsFlutterBinding.ensureInitialized();

  FlutterNativeSplash.preserve(
    widgetsBinding: WidgetsFlutterBinding.ensureInitialized(),
  );

  // initializing firebase app
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  HttpOverrides.global = MyHttpOverrides();

  await Isar.open(
    [UserModelSchema],
    inspector: true,
  );
  await IsarUserModelManager.putDefaultModel();
  // await IsarUserModelManager.setIsFirstLaunchToTrue();

  //main app
  runApp(
    ProviderScope(
      child: MaterialApp.router(
        debugShowCheckedModeBanner: false,
        routerConfig: _router,
      ),
    ),
  );

  //removing native splash
  FlutterNativeSplash.remove();

  //<----End---->
}

what I've tried flutter pub run flutter_native_splash:remove flutter pub run flutter_native_splash:create

jonbhanson commented 1 year ago

What version of Android are you using? If you are using Android 12+ you need a config section specific to Android 12 since it handles the splash screen differently from prior version.

AbdulHaseeeb commented 1 year ago

I've tested it on android 7. I think this command messed up something flutter pub run flutter_native_splash:remove

I ran these three commands one after the other flutter clean flutter pub get flutter pub run flutter_native_splash:create

I cannot reconfigure it, It have stopped working. Everytime I reinstall it and reset everything, with new image and all, it keeps showing blue screen.

what I've tried,

  1. flutter pub run flutter_native_splash:remove
  2. removing package
  3. running flutter clean
  4. flutter pub get
  5. reinstalling
  6. flutter clean
  7. flutter pub get
  8. running flutter pub run flutter_native_splash:create
  9. with right configuration (setting color, image etc)

I'll be grateful if you'll explain why you've made it this way i.e write things in pubspec.yaml why not like this (excuse me I'm a beginner)

FlutterNativeSplash.preserve(
    widgetsBinding: WidgetsFlutterBinding.ensureInitialized(),
    widgetToDisplayWhenAppInitializes: Widget(),
    android: true, 
    ios: true, 
    more_properties: ...,     
  );

//once everything initialize FlutterNativeSplash.remove();

AbdulSamadgithub commented 1 year ago

It was not working on my app too when I changed my image. I think the proper way to do it is to use "remove" first and remove everything and then use "create" to create splash screen.

What I did to solve this is to create a new project in a different directory and then transfer all files from lib, copying dependencies from pubspec.yaml. and then use this package again to create splash screen.

jonbhanson commented 1 year ago

You should not need to user the flutter pub run flutter_native_splash:remove command to change your splash image. flutter pub run flutter_native_splash:create will overwrite your splash image with a new one based on your pubspec.yaml settings.

In answer to your question @AbdulHaseeeb about why the app is configured this way. On Android for example, the command line part of this package (flutter pub run flutter_native_splash:create) must modify the images in the android folder of the app. These files are then compiled into an appbundle and placed on the play store. Then, when the end user runs the app, the FlutterNativeSplash.preserve() code executes. At this point, it is too late to modify the splash image. It has already been baked into the app and displayed by the native platform before the FlutterNativeSplash.preserve() code was executed. The preserve() and remove() commands simply allows the splash to continue to be displayed while you load app resources and then control when the splash screen is removed to present your app.

Please send me your app code if you would like me to try to figure out why this package is not configuring it correctly.

AbdulSamadgithub commented 1 year ago

I did what @AbdulSamadgithub said and fixed it. Thank you though.

jonbhanson commented 1 year ago

AbdulSamadgithub commented last week I did what @AbdulSamadgithub said and fixed it. Thank you though.

I think you posted that from the wrong account. 😆 Glad you resolved it.

Marmik123 commented 1 year ago

I did what @AbdulSamadgithub said and fixed it. Thank you though.

please tell me what you did facing the same issue