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)
Comments
-
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 over 4 yearsIt works, thanks so much mate! You're awesome! Btw is possible to add Color blend mode as well in it?
-
nmanikiran over 4 years@leemuljadi check this link stackoverflow.com/questions/52922775/…, i haven't tried
-
leemuljadi over 4 yearsI ended up using link ColorFiltered( colorFilter: ColorFilter.mode(Colors.red.withOpacity(0.4), BlendMode.srcOver), child: YourWidget(), ) Thanks mate for the advise!
-
Alex Semeniuk almost 3 yearsThe first one works, thanks. The second one does not, since compiler does not automatically consider
AssetImage
to be anImageProvider
(probably because of generalization), and using ofas
operator is discouraged.