DART中可以有配置文件吗? [英] is possible have a configuration file in DART?
本文介绍了DART中可以有配置文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个JavaScript类:
I have this JavaScript class:
'use strict;'
/* global conf */
var properties = {
'PROPERTIES': {
'CHANNEL': 'sport',
'VIEW_ELEMENTS': {
'LOADER_CLASS': '.loader',
'SPLASH_CLASS': '.splash'
}
}
};
在JavaScript中,我可以使用以下属性: properties.PROPERTIES.CHANNEL
In JavaScript I can use these properties: properties.PROPERTIES.CHANNEL
是否可以将其转换为DART?
Is it possible to convert this to DART? Is there a best practise to do that?
推荐答案
有不同的方法。
您可以只创建一个地图
my_config.dart
const Map properties = const {
'CHANNEL': 'sport',
'VIEW_ELEMENTS': const {
'LOADER_CLASS': '.loader',
'SPLASH_CLASS': '.splash'
}
}
然后使用它
main.dart
import 'my_config.dart';
main() {
print(properties['VIEW_ELEMENTS']['SPLASH_CLASS']);
}
或者您可以使用类来获取正确的自动完成和类型检查
or you can use classes to get proper autocompletion and type checking
my_config.dart
const properties = const Properties('sport', const ViewElements('.loader', '.splash'));
class Properties {
final String channel;
final ViewElements viewElements;
const Properties(this.channel, this.viewElements;
}
class ViewElements {
final String loaderClass;
final String splashClass;
const ViewElements(this.loaderClass, this.splashClass);
}
main.dart
import 'my_config.dart';
main() {
print(properties.viewElements.splashClass);
}
这篇关于DART中可以有配置文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文