How to pass image asset in imageprovider type?

8,372

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

Image.asset(AppAsset.background).image

Or

AssetImage(AppAsset.background)

Share:
8,372
leemuljadi
Author by

leemuljadi

From 'Hello World' to 'Change the World'.

Updated on December 14, 2022

Comments

  • leemuljadi
    leemuljadi over 1 year

    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
    leemuljadi over 4 years
    It works, thanks so much mate! You're awesome! Btw is possible to add Color blend mode as well in it?
  • nmanikiran
    nmanikiran over 4 years
    @leemuljadi check this link stackoverflow.com/questions/52922775/…, i haven't tried
  • leemuljadi
    leemuljadi over 4 years
    I ended up using link ColorFiltered( colorFilter: ColorFilter.mode(Colors.red.withOpacity(0.4), BlendMode.srcOver), child: YourWidget(), ) Thanks mate for the advise!
  • Alex Semeniuk
    Alex Semeniuk almost 3 years
    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.