flutter_native_splash icon indicating copy to clipboard operation
flutter_native_splash copied to clipboard

Hot restart on web throws exception that cannot be caught

Open sunilguptasg opened this issue 1 year ago • 1 comments

Describe the bug main.dart

  try {
    FlutterNativeSplash.remove();
  } catch (e) {
    debugPrint(e.toString());
  }

Hot restart (web):

Error: PlatformException(error, Exception: Did you forget to run "dart run flutter_native_splash:create"? 
 Could not run the JS command removeSplashFromWeb(), null, null)
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:3  throw_
packages/flutter/src/services/message_codecs.dart 651:7                      decodeEnvelope
packages/flutter/src/services/platform_channel.dart 322:18                   _invokeMethod
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50           <fn>
dart-sdk/lib/async/zone.dart 1661:54                                         runUnary

Configuration

flutter_native_splash:
  color: "#002f54"
  image: assets/images/splash/tuotr_logo_splash_screen_dark.png
  color_dark: "#002f54"
  image_dark: assets/images/splash/tuotr_logo_splash_screen_dark.png
  #background_image_web: assets/images/splash/tuotr_logo_splash_screen_dark.png
  #background_image_dark_web: assets/images/splash/tuotr_logo_splash_screen_dark.png
  web_image_mode: center
  fullscreen: false
  android: true
  ios: true
  android_12:
    color: "#ffffff"
    color_dark: "#002f54"
    image: assets/images/splash/android12splash.png
    image_dark: assets/images/splash/android12splash.png

Device (please complete the following information):

  • web (Chrome)

To Reproduce Steps to reproduce the behavior, using the example app:

  1. add the FlutterNativeSplash.remove() in main.dart
  2. launch Chrome - no issues
  3. restart - uncaught exception

sunilguptasg avatar Dec 29 '23 09:12 sunilguptasg

Same issue

adonisRodxander avatar Jan 10 '24 15:01 adonisRodxander

Have you run dart run flutter_native_splash:create?

jonbhanson avatar Jan 28 '24 15:01 jonbhanson

Yes, the splash screen works correctly, but when the hot reload is done the error occurs

adonisRodxander avatar Jan 28 '24 15:01 adonisRodxander

Thanks for the response. This package adds the following code to the web's index.html:

  <script id="splash-screen-script">
    function removeSplashFromWeb() {
      document.getElementById("splash")?.remove();
      document.getElementById("splash-branding")?.remove();
      document.body.style.background = "transparent";
    }
  </script>

The error shown above seems to indicate this script was not added to index.html. Can you conform if it is present?

jonbhanson avatar Jan 28 '24 16:01 jonbhanson

Yes, I have that script, I made some modifications to achieve a better transition, smoother...that could be the problem, if I use the code you provided me, it works perfect...

<script id="splash-screen-script">
    function removeSplashFromWeb() {
      const splashElement = document.getElementById("splash");
      splashElement.classList.add("remove");
      setTimeout(function () {
        splashElement.remove();
        document.getElementById("splash-screen-script")?.remove();
      }, 750 /* animation time + wait rendering and others(500ms) */);
    }
  </script>

Could you help me?

adonisRodxander avatar Jan 28 '24 16:01 adonisRodxander

@adonisRodxander sorry, I'm not sure why that code is not working. @sunilguptasg have you run dart run flutter_native_splash:create. Or have you modified index.html?

jonbhanson avatar Jan 28 '24 17:01 jonbhanson

Closed due to inactivity. Feel free to reopen if you are still having trouble.

jonbhanson avatar Feb 04 '24 15:02 jonbhanson