feat(location): Make flag getter a part of server provider location object

pull/238/head
NaiJi ✨ 2023-07-17 12:23:17 -03:00
parent 6453257aa3
commit cbef1d578b
6 changed files with 61 additions and 66 deletions

View File

@ -36,6 +36,43 @@ class DigitalOceanLocation {
static DigitalOceanLocation fromJson(final Map<String, dynamic> json) =>
_$DigitalOceanLocationFromJson(json);
String get flag {
String emoji = '';
switch (slug.substring(0, 3)) {
case 'fra':
emoji = '🇩🇪';
break;
case 'ams':
emoji = '🇳🇱';
break;
case 'sgp':
emoji = '🇸🇬';
break;
case 'lon':
emoji = '🇬🇧';
break;
case 'tor':
emoji = '🇨🇦';
break;
case 'blr':
emoji = '🇮🇳';
break;
case 'nyc':
case 'sfo':
emoji = '🇺🇸';
break;
}
return emoji;
}
}
@JsonSerializable()

View File

@ -135,6 +135,24 @@ class HetznerLocation {
static HetznerLocation fromJson(final Map<String, dynamic> json) =>
_$HetznerLocationFromJson(json);
String get flag {
String emoji = '';
switch (country.substring(0, 2)) {
case 'DE':
emoji = '🇩🇪';
break;
case 'FI':
emoji = '🇫🇮';
break;
case 'US':
emoji = '🇺🇸';
break;
}
return emoji;
}
}
/// A Volume is a highly-available, scalable, and SSD-based block storage for Servers.

View File

@ -3,13 +3,11 @@ class ServerProviderLocation {
required this.title,
required this.identifier,
this.description,
this.flag,
this.flag = '',
});
final String title;
final String identifier;
final String? description;
/// as emoji
final String? flag;
final String flag;
}

View File

@ -293,43 +293,6 @@ class DigitalOceanServerProvider extends ServerProvider {
return success;
}
String? getEmojiFlag(final String query) {
String? emoji;
switch (query.toLowerCase().substring(0, 3)) {
case 'fra':
emoji = '🇩🇪';
break;
case 'ams':
emoji = '🇳🇱';
break;
case 'sgp':
emoji = '🇸🇬';
break;
case 'lon':
emoji = '🇬🇧';
break;
case 'tor':
emoji = '🇨🇦';
break;
case 'blr':
emoji = '🇮🇳';
break;
case 'nyc':
case 'sfo':
emoji = '🇺🇸';
break;
}
return emoji;
}
@override
Future<GenericResult<List<ServerProviderLocation>>>
getAvailableLocations() async {
@ -351,7 +314,7 @@ class DigitalOceanServerProvider extends ServerProvider {
location = ServerProviderLocation(
title: rawLocation.slug,
description: rawLocation.name,
flag: getEmojiFlag(rawLocation.slug),
flag: rawLocation.flag,
identifier: rawLocation.slug,
);
} catch (e) {
@ -662,8 +625,7 @@ class DigitalOceanServerProvider extends ServerProvider {
ServerMetadataEntity(
type: MetadataType.location,
trId: 'server.location',
value:
'${droplet['region']['name']} ${getEmojiFlag(droplet['region']['slug'].toString()) ?? ''}',
value: '${droplet['region']['name']}',
),
ServerMetadataEntity(
type: MetadataType.other,

View File

@ -335,26 +335,6 @@ class HetznerServerProvider extends ServerProvider {
return result;
}
String? getEmojiFlag(final String query) {
String? emoji;
switch (query.toLowerCase()) {
case 'de':
emoji = '🇩🇪';
break;
case 'fi':
emoji = '🇫🇮';
break;
case 'us':
emoji = '🇺🇸';
break;
}
return emoji;
}
@override
Future<GenericResult<bool>> trySetServerLocation(
final String location,
@ -396,7 +376,7 @@ class HetznerServerProvider extends ServerProvider {
location = ServerProviderLocation(
title: rawLocation.city,
description: rawLocation.description,
flag: getEmojiFlag(rawLocation.country),
flag: rawLocation.flag,
identifier: rawLocation.name,
);
} catch (e) {

View File

@ -107,7 +107,7 @@ class SelectLocationPage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${location.flag ?? ''} ${location.title}',
'${location.flag} ${location.title}',
style: Theme.of(context)
.textTheme
.titleMedium,