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) => static DigitalOceanLocation fromJson(final Map<String, dynamic> json) =>
_$DigitalOceanLocationFromJson(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() @JsonSerializable()

View File

@ -135,6 +135,24 @@ class HetznerLocation {
static HetznerLocation fromJson(final Map<String, dynamic> json) => static HetznerLocation fromJson(final Map<String, dynamic> json) =>
_$HetznerLocationFromJson(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. /// 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.title,
required this.identifier, required this.identifier,
this.description, this.description,
this.flag, this.flag = '',
}); });
final String title; final String title;
final String identifier; final String identifier;
final String? description; final String? description;
final String flag;
/// as emoji
final String? flag;
} }

View File

@ -293,43 +293,6 @@ class DigitalOceanServerProvider extends ServerProvider {
return success; 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 @override
Future<GenericResult<List<ServerProviderLocation>>> Future<GenericResult<List<ServerProviderLocation>>>
getAvailableLocations() async { getAvailableLocations() async {
@ -351,7 +314,7 @@ class DigitalOceanServerProvider extends ServerProvider {
location = ServerProviderLocation( location = ServerProviderLocation(
title: rawLocation.slug, title: rawLocation.slug,
description: rawLocation.name, description: rawLocation.name,
flag: getEmojiFlag(rawLocation.slug), flag: rawLocation.flag,
identifier: rawLocation.slug, identifier: rawLocation.slug,
); );
} catch (e) { } catch (e) {
@ -662,8 +625,7 @@ class DigitalOceanServerProvider extends ServerProvider {
ServerMetadataEntity( ServerMetadataEntity(
type: MetadataType.location, type: MetadataType.location,
trId: 'server.location', trId: 'server.location',
value: value: '${droplet['region']['name']}',
'${droplet['region']['name']} ${getEmojiFlag(droplet['region']['slug'].toString()) ?? ''}',
), ),
ServerMetadataEntity( ServerMetadataEntity(
type: MetadataType.other, type: MetadataType.other,

View File

@ -335,26 +335,6 @@ class HetznerServerProvider extends ServerProvider {
return result; 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 @override
Future<GenericResult<bool>> trySetServerLocation( Future<GenericResult<bool>> trySetServerLocation(
final String location, final String location,
@ -396,7 +376,7 @@ class HetznerServerProvider extends ServerProvider {
location = ServerProviderLocation( location = ServerProviderLocation(
title: rawLocation.city, title: rawLocation.city,
description: rawLocation.description, description: rawLocation.description,
flag: getEmojiFlag(rawLocation.country), flag: rawLocation.flag,
identifier: rawLocation.name, identifier: rawLocation.name,
); );
} catch (e) { } catch (e) {

View File

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