23

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.

leemuljadi
  • 410
  • 1
  • 3
  • 14

1 Answers1

52

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

Image.asset(AppAsset.background).image

Or

AssetImage(AppAsset.background)

nmanikiran
  • 2,866
  • 15
  • 19
  • It works, thanks so much mate! You're awesome! Btw is possible to add Color blend mode as well in it? – leemuljadi Oct 17 '19 at 11:48
  • @leemuljadi check this link https://stackoverflow.com/questions/52922775/changing-background-color-of-image-in-flutter#answers, i haven't tried – nmanikiran Oct 17 '19 at 12:25
  • 1
    I ended up using [link](https://stackoverflow.com/questions/51190657/flutter-how-to-blend-an-image-with-a-gradient-colour) ColorFiltered( colorFilter: ColorFilter.mode(Colors.red.withOpacity(0.4), BlendMode.srcOver), child: YourWidget(), ) Thanks mate for the advise! – leemuljadi Oct 17 '19 at 15:33
  • The first one works, thanks. The second one does not, since compiler does not automatically consider `AssetImage` to be an `ImageProvider` (probably because of generalization), and using of `as` operator is discouraged. – Alex Semeniuk Jul 21 '21 at 07:14