flutter_native_splash
flutter_native_splash copied to clipboard
Hot restart on web throws exception that cannot be caught
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:
- add the FlutterNativeSplash.remove() in main.dart
- launch Chrome - no issues
- restart - uncaught exception
Same issue
Have you run dart run flutter_native_splash:create
?
Yes, the splash screen works correctly, but when the hot reload is done the error occurs
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?
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 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?
Closed due to inactivity. Feel free to reopen if you are still having trouble.