country_pickers icon indicating copy to clipboard operation
country_pickers copied to clipboard

Can i precache used flag images?

Open dukaric1991 opened this issue 5 years ago • 1 comments

Can i precache images/flags on app start, like i do with my own assets:

precacheImage(new AssetImage("assets/img/image1.jpg"), context);
precacheImage(new AssetImage("assets/img/image2.jpg"), context);

because when i first come to the screen where i use this country_picker flags/images, the images flashes/loads/pops up, and then after that everything is ok.

dukaric1991 avatar Mar 18 '19 12:03 dukaric1991

Hi @dukaric1991 ! You need to set package field to access the assets(images) of another package as following:

static String getFlagImageAssetPath(String isoCode) {
   return "assets/${isoCode.toLowerCase()}.png";
 }

 static Widget getDefaultFlagImage(Country country) {
   return Image.asset(
     CountryPickerUtils.getFlagImageAssetPath(country.isoCode),
     height: 20.0,
     width: 30.0,
     fit: BoxFit.fill,
     package: "country_pickers",
   );
 } 

You can have a look at here: https://github.com/figengungor/country_pickers/blob/master/lib/utils/utils.dart

figengungor avatar Mar 18 '19 12:03 figengungor