I am using animated_splash_screen: ^1.2.0 to build a splash screen for my flutter app. Well the animation did happen, but the image won't load. Here is my code:
class Splash extends StatelessWidget {
const Splash({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return AnimatedSplashScreen(
splash: 'assets/pictures/logo.png',
duration: 3000,
nextScreen: MyApp(),
splashTransition: SplashTransition.rotationTransition);
}
}
and this is the exception I got:
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ The following assertion was thrown resolving an image codec: Unable to load asset: assets/pictures/logo.png When the exception was thrown, this was the stack: #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:237:7) <asynchronous suspension> #1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:675:14) <asynchronous suspension> Image provider: AssetImage(bundle: null, name: "assets/pictures/logo.png") Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#cb75e(), name: "assets/pictures/logo.png", scale: 1.0)
CodePudding user response:
Turns out I didn't know I have to add a tag to pubspec.yaml
assets:
- assets/audio/
- assets/pictures/
this fixed the problem
CodePudding user response:
///Please check your pubsec.yml add your image folder in it like this
assets:
- assets/pictures/
///please check in your project assets folder the image file.
///and also check image name should be same as same you define as in stateless widget
class Splash extends StatelessWidget {
const Splash({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return AnimatedSplashScreen(
splash: 'assets/pictures/logo.png',
duration: 3000,
nextScreen: MyApp(),
splashTransition: SplashTransition.rotationTransition);
}
}