运行dartdoc命令:生成如下文件目录
代码演示:
/// 配置路由////// 将初始化路由设为[Tabs()]final routes = {'/': (context) => Tabs(),'/search': (context) => SearchPage(),'/productList': (context, {arguments}) =>ProductListPage(arguments: arguments),};
生成文档:(中括号内容会生成一个链接,可点击)
点击后:
class Tabs extends StatefulWidget {Tabs({Key key}) : super(key: key);_TabsState createState() => _TabsState();}
文档:可以清晰看到结构体会自动表明为constructor
对于类内方法:
/// 设置适配高度static height(double value) {return ScreenUtil().setHeight(value);}/// 设置适配宽度static width(double value) {return ScreenUtil().setWidth(value);}/// 获取适配高度static getScreenHeight() {return ScreenUtil().screenHeight;}
文档:
代码块
/// 仓库层////// 当请求开始时:处理ViewModel层传递过来的参数/// 当返回数据时:将网络和本地的数据组装成ViewModel层需要的数据类型class GithubRepo {final GithubService _remote;/// sharedPreference////// 也应该算在Model层,在这里面处理数据的读取final SpUtil _sp;GithubRepo(this._remote, this._sp);/// 登录////// - 将ViewModel层 传递过来的[username] 和 [password] 处理为 token 并用[SharedPreferences]进行缓存/// - 调用 [_remote] 的 [login] 方法进行网络访问/// - 返回 [Observable] 给ViewModel层Observable login(String username, String password) {_sp.putString(KEY_TOKEN, "basic " + base64Encode(utf8.encode('$username:$password')));return _remote.login();}}
生成文档:
