Skip to content

Commit a90a095

Browse files
authored
chore: Use enum features (#398)
1 parent 79ea870 commit a90a095

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

examples/fullstack/frontend/lib/config.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,20 @@ enum Environment {
2121
prod,
2222
}
2323

24-
extension EnumToString on Environment {
25-
String toName() => toString().split('.').last;
26-
}
27-
28-
Environment parseEnvironment(String env) => switch (env) {
29-
'dev' => Environment.dev,
30-
'prod' => Environment.prod,
31-
_ => throw Exception("Parsing as Environment enum exception: '$env'")
32-
};
33-
3424
class Config {
3525
final String greetingsUrl;
3626

3727
Config({required this.greetingsUrl});
3828

3929
static Future<Config> load(Environment env) async {
40-
final file = 'assets/config/${env.toName()}.json';
30+
final file = 'assets/config/${env.name}.json';
4131
final data = await rootBundle.loadString(file);
4232
final json = jsonDecode(data) as Map<String, dynamic>;
4333
return Config(greetingsUrl: json['greetingUrl'] as String);
4434
}
4535

4636
static Future<Config> parse(String environment) async {
47-
final env = parseEnvironment(environment);
37+
final env = Environment.values.byName(environment);
4838
return await load(env);
4939
}
5040
}

0 commit comments

Comments
 (0)