Search code examples
imageflutterdartassets

How to pass image asset in imageprovider type?


I currently depend on splashscreen 1.2.0 package for the a flutter app. But the backgroundimage variable type is imageprovider, whereas I want to use the image from assets folder. Does anyone know how to pass the image asset file to be able to use as the imageprovider type or maybe any other way to make it work?

Cause using the imageprovider it just loaded a bit later on compared to the other properties.

Many thanks!

I've tried using the Image.asset() but didn't work.

return SplashScreen(
    seconds: 5,
    navigateAfterSeconds: AppRoute,
    title: Text('Welcome', style: AppTextStyle),
    image: Image.asset(AppAsset.logo),
    photoSize: AppScreen,
    imageBackground: Image.asset(AppAsset.background),
    loaderColor: AppColor,
    loadingText: Text('Loading'),
    styleTextUnderTheLoader: AppTextStyle,
    onClick: () {},
 );

Expected to be able to use Image.assets but it only works for the network image.


Solution

  • Try changing the Image.asset(AppAsset.background) to as follows

    Image.asset(AppAsset.background).image

    Or

    AssetImage(AppAsset.background)