生成文档:
1. flutter的文档使用dartdoc生成,dart sdk自带了dartdoc,下载dart sdk后将bin目录添加到path环境变量中。
2. 进入flutter/packages/flutter 目录下调用 dartdoc提示错误如下:
Generation failed: pub get failed: Resolving dependencies...
Because flutter depends on flutter_goldens any from sdk which doesn't exist (the Flutter SDK is not available), version solving failed.
Flutter users should run `flutter packages get` instead of `pub get`..
运行 flutter packages get 会自动生成 .packages文件即可解决。
3. 修改dart-sdk\bin\snapshots\resources\dartdoc\templates 下的html模板,去除文档底部及左侧列表。修改如下:
_footer.html 移除
<footer>
<span class="no-break">
{{packageGraph.name}} {{packageGraph.version}}
</span><!-- footer-text placeholder -->
</footer>
移除所有html文件中的
<div class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
<h5><span class="package-name">{{self.name}}</span> <span class="package-kind">{{self.kind}}</span></h5>
{{>packages}}
</div>
4. 生成 docSet.dsidx 索引文件,dartdoc会生成index.json文件,通过该文件生成docSet.dsidx 转换代码如下:
#!/usr/local/bin/python
import sqlite3
import json
conn = sqlite3.connect('docSet.dsidx')
cur = conn.cursor()
try: cur.execute('DROP TABLE searchIndex;')
except: pass
cur.execute('CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);')
cur.execute('CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);')
f = open("Documents/flutter/index.json")
setting = json.load(f)
for i, val in enumerate(setting):
if val['qualifiedName']:
name='flutter:'+val['qualifiedName']
type=''
path='flutter/'+val['href']
if val['type']=='library':
type='Library'
elif val['type']=='constructor':
type='Constructor'
elif val['type']=='method':
type='Method'
elif val['type']=='property':
type='Property'
elif val['type']=='class':
type='Class'
elif val['type']=='typedef':
type='Type'
elif val['type']=='enum':
type='Enum'
elif val['type']=='constant':
type='Constant'
elif val['type']=='function':
type='Function'
elif val['type']=='top-level property':
type='Property'
elif val['type']=='top-level constant':
type='Constant'
cur.execute('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?,?,?)', (name, type, path))
conn.commit()
conn.close()
最终的文档下载地址如下:
下载地址:百度云