resource_manager 1.0.1 resource_manager: ^1.0.1 copied to clipboard
Library of resource manager.
resource_manager #
This is a library of Flutter for resource manager works as similar as what Android does. It works with JSON file.
使用JSON文件的类Android的Flutter资源管理库。
How to use #
-
Use
initBaseResources(double devicePixelRatio, String baseResourceFile)
to init the base resources from JSON file.
使用initBaseResources(double devicePixelRatio, String baseResourceFile)
从指定JSON文件初始化基础资源。
eg.,initBaseResources(window.devicePixelRatio, 'res/values.json')
-
Use
getResources(String jsonFile)
to get resources from JSON file.
使用getResources(String jsonFile)
从JSON文件获取资源。
eg.,getResources('res/example.json')
-
Use
getXXX(String name, {Resources fromResources})
to get the resource by name.
使用getXXX(String name, {Resources fromResources})
获取指定名称资源。
JSON file #
The JSON file for resources has nodes named dimens, colors, drawable, strings, integers, doubles.
资源JSON文件的节点有dimens, colors, drawable, strings, integers, doubles。
eg.,
{
"dimens": {
"h1_text_size": "32dp",
"h2_text_size": "24dp",
"h3_text_size": "19dp",
"h4_text_size": "16dp",
"h5_text_size": "14dp",
"h6_text_size": "13dp"
},
"colors": {
"black": "#000000",
"FireBrick": "#B22222",
"DeepPink": "#FF1493",
"Gold": "#FFD700",
"OliveDrab": "#6B8E23",
"Lime": "#00FF00",
"RoyalBlue": "#4169E1",
"DarkOrchid": "#9932CC"
},
"drawable": {
"logo": "graphics/FlutterDart.png"
},
"strings": {
"string 1": "base string 1"
},
"integers": {
"integer 1": 10,
"integer 2": 20
},
"doubles": {
"double 1": 30.3,
"double 2": 40
}
}
Value can be a string with prefix, such @dimen/, @color/, @drawable/, @string/, @integer/ and @double/, and then refer to another resource. If the resource can't be find in the referred resources, it would keep looking for the resource in the base resources.
值可以是有__@dimen/__, @color/, @drawable/, @string/, @integer/ 和 @double/ 为前缀的字符串,指向其他资源。当在指定资源文件中找不到指定名称资源时,继续在基础资源文件中寻找。
Methods for getting resource #
getDimension(String name, {Resources fromResources, Set<String> soughtNames})
getColor(String name, {Resources fromResources, Set<String> soughtNames})
getDrawable(String name, {Resources fromResources, Set<String> soughtNames})
getString(String name, {Resources fromResources, Set<String> soughtNames})
getInteger(String name, {Resources fromResources, Set<String> soughtNames})
getDouble(String name, {Resources fromResources, Set<String> soughtNames})
If optional parameter fromResources is ignored, then the methods would try to get resources from base resource file.
如果忽略可选参数fromResources,则直接从基础资源文件中寻找。
Ignore optional parameter soughtNames, please. 请忽略可选参数soughtNames。