当前位置:
首页
文章
前端
详情

Flutter && Dart

/// Dart 弱类型(var、object、dynamic)
/// Dart中没有=== 运算符。
/// 简介写法:
/// 三元运算符??: t ?? 'test'是t!=null ? t : 'test'的缩写。
/// 级联操作符(依次进行调用),允许对同一对象或函数进行一系列操作,testObj.add('t')..delete('d')..show();

类: 命名构造函数
class Dog{
    String color;
    Dog.red(){this.color='red';}
    Dog.black(){this.color='black';}
}
void main(List<String> args) {
    Dog redDog = new Dog.red();
    print(redDog.color);
    Dog blackDog = new Dog.black();
    print(blackDog.color);
}

Flutter 命名规范:

  1. AaBb类规范
    首字母大写驼峰命名法,类似IsClassName,用于类的命名。
  2. aaBb类规范
    首字母小写驼峰,isParamName,用于常量和变量命名。
  3. aa_bb类规范
    小写字母下换线连接法,如is_file_name,用于文件和文件夹命名。

注释文档生成,在As的Terminal中打开命令行窗口,运行命令 dartdoc,
会在当前目录中生成doc的文件夹,里面有生成的html文档。

组件:
ClipRRect:圆角组件,让子组件有原形变焦。
Container:布局组件,容器组件。类似前端的body。
Expanded:按比例拉伸,
Padding:填充空白区域,

ListView下拉刷新组件:RefreshIndicator,onRefresh方法中触发刷新事件。
上拉加载更多。
_scrollControllser.addListener((){
    if(!hasMore) return;
    if(!isLoading && _scrollControllser.position.pixels 
        >= _scrollControllser.position.maxScrollExtent) {
        isLoading = true;
        loadMoreData();
    }
});
/// 加载更多。
void loadMoreData() {
    StructApiContentListRetInfo retInfo = ApiContentInndex().getRecomList(lastId);
    List<StructContentDetail> newList = retInfo.data;
    setState((){
        isLoading=false;
        hasMore = retInfo.hasMore;
        contentList.addAll(newList);
    });
}

免责申明:本站发布的内容(图片、视频和文字)以转载和分享为主,文章观点不代表本站立场,如涉及侵权请联系站长邮箱:xbc-online@qq.com进行反馈,一经查实,将立刻删除涉嫌侵权内容。