Skip to content

Commit adbf187

Browse files
committed
update
1 parent e74ae94 commit adbf187

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

assets/country-flags/svg/za.svg

Lines changed: 18 additions & 1 deletion
Loading

lib/src/country_code.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,19 @@ enum CountryCode {
285285
//
286286
//
287287

288-
String get assetPath {
288+
String get countryCode {
289289
final code = name.toLowerCase().replaceAll('_', '-');
290+
return code;
291+
}
292+
293+
//
294+
//
295+
//
296+
297+
String get assetPath {
290298
if (custom) {
291-
return 'packages/df_country_flags/assets/custom/svg/$code.svg';
299+
return 'packages/df_country_flags/assets/custom/svg/$countryCode.svg';
292300
}
293-
return 'packages/df_country_flags/assets/country-flags/svg/$code.svg';
301+
return 'packages/df_country_flags/assets/country-flags/svg/$countryCode.svg';
294302
}
295303
}

lib/src/country_flag_builder.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)