@@ -25,6 +25,7 @@ class CountryFlagBuilder extends StatelessWidget {
2525 //
2626 //
2727
28+ final String cacheKey;
2829 final CountryCode countryCode;
2930 final double ? width;
3031 final double ? height;
@@ -37,6 +38,7 @@ class CountryFlagBuilder extends StatelessWidget {
3738
3839 const CountryFlagBuilder ({
3940 super .key,
41+ this .cacheKey = 'df_country_flags' ,
4042 this .width,
4143 this .height,
4244 required this .countryCode,
@@ -48,11 +50,12 @@ class CountryFlagBuilder extends StatelessWidget {
4850 //
4951 //
5052
51- Future <Uint8List > _loadSvg (BuildContext context, String assetPath ) async {
53+ Future <Uint8List > _loadSvg (BuildContext context) async {
5254 final p = await SharedPreferences .getInstance ();
53- final cacheKey = 'svg_$assetPath ' ;
55+ final assetPath = countryCode.assetPath;
56+ final cacheKey1 = '${cacheKey }_${countryCode .name }' ;
5457 try {
55- final base64String = p.getString (cacheKey );
58+ final base64String = p.getString (cacheKey1 );
5659 if (base64String != null ) {
5760 final byteData = base64Decode (base64String);
5861 return byteData;
@@ -70,7 +73,7 @@ class CountryFlagBuilder extends StatelessWidget {
7073 debugPrint ('[df_country_flags] Loaded from assets: $assetPath ' );
7174 try {
7275 final base64String = base64Encode (byteData);
73- await p.setString (cacheKey , base64String);
76+ await p.setString (cacheKey1 , base64String);
7477 } catch (e) {
7578 log ('Error writing cache: $e ' , name: 'df_country_flags' );
7679 }
@@ -98,7 +101,7 @@ class CountryFlagBuilder extends StatelessWidget {
98101 @override
99102 Widget build (BuildContext context) {
100103 return FutureBuilder <Uint8List >(
101- future: _loadSvg (context, countryCode.assetPath ),
104+ future: _loadSvg (context),
102105 builder: (context, snapshot) {
103106 if (snapshot.hasData) {
104107 return builder (context, snapshot.data! );
0 commit comments