写点什么

Flutter 自适应瀑布流,深入浅出安卓开发

用户头像
Android架构
关注
发布于: 刚刚

),


);


if (!konwSized) {


//todo: not work in web


loadingWidget = AspectRatio(


aspectRatio: 1.0,


child: loadingWidget,


);


}


return loadingWidget;


} else if (value.extendedImageLoadState == LoadState.completed) {


item.imageRawSize = Size(


value.extendedImageInfo.image.width.toDouble(),


value.extendedImageInfo.image.height.toDouble());


}


return null;


},


),


Positioned(


top: 5.0,


right: 5.0,


child: Container(


padding: const EdgeInsets.all(3.0),


decoration: BoxDecoration(


color: Colors.grey.withOpacity(0.6),


border: Border.all(color: Colors.grey.withOpacity(0.4), width: 1.0),


borderRadius: const BorderRadius.all(


Radius.circular(5.0),


),


),


child: Text(


'${index + 1}',


textAlign: TextAlign.center,


style: const TextStyle(fontSize: fontSize, color: Colors.white),


),


),


)


],


);


if (konwSized) {


image = AspectRatio(


aspectRatio: item.imageSize.width / item.imageSize.height,


child: image,


);


} else if (item.imageRawSize != null) {


image = AspectRatio(


aspectRatio: item.imageRawSize.width / item.imageRawSize.height,


child: image,


);


}


return Column(


crossAxisAlignment: CrossAxisAlignment.start,


children: <Widget>[


image,


const SizedBox(


height: 5.0,


),


buildTagsWidget(item),


const SizedBox(


height: 5.0,


),


buildBottomWidget(item),


],


);


}

2.自适应标签:

Widget buildTagsWidget(


TuChongItem item, {


int maxNum = 6,


}) {


const double fontSize = 12.0;


return Wrap(


runSpacing: 5.0,


spacing: 5.0,


children: item.tags.take(maxNum).map<Widget>((String tag) {


final Color color = item.tagColors[item.tags.indexOf(tag)];


return Container(


padding: const EdgeInsets.all(3.0),


decoration: BoxDecoration(


color: color,


border: Border.all(color: Colors.grey.withOpacity(0.4), width: 1.0),


borderRadius: const BorderRadius.all(


Radius.circular(5.0),


),


),


child: Text(


tag,


textAlign: TextAlign.start,


style: TextStyle(


fontSize: fontSize,


color: color.computeLuminance() < 0.5


? Colors.white


: Colors.black),


),


);


}).toList());


}

3.上拉刷新和下拉加载

class PullToRefreshHeader extends StatelessWidget {


const PullToRefreshHeader(this.info, this.lastRefreshTime, {this.color});


final PullToRefreshScrollNotificationInfo info;


final DateTime lastRefreshTime;


final Color color;


@override


Widget build(BuildContext context) {


if (info == null) {


return Container();


}


String text = '';


if (info.mode == RefreshIndicatorMode.armed) {


text = 'Release to refresh';


} else


《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
浏览器打开:qq.cn.hn/FTe 免费领取
复制代码


if (info.mode == RefreshIndicatorMode.refresh ||


info.mode == RefreshIndicatorMode.snap) {


text = 'Loading...';


} else if (info.mode == RefreshIndicatorMode.done) {


text = 'Refresh completed.';


} else if (info.mode == RefreshIndicatorMode.drag) {


text = 'Pull to refresh';


} else if (info.mode == RefreshIndicatorMode.canceled) {


text = 'Cancel refresh';


}


final TextStyle ts = const TextStyle(


color: Colors.grey,


).copyWith(fontSize: 13);


final double dragOffset = info?.dragOffset ?? 0.0;


final DateTime time = lastRefreshTime ?? DateTime.now();


final double top = -hideHeight + dragOffset;


return Container(


height: dragOffset,


color: color ?? Colors.transparent,


//padding: EdgeInsets.only(top: dragOffset / 3),


//padding: EdgeInsets.only(bottom: 5.0),


child: Stack(


children: <Widget>[


Positioned(


left: 0.0,


right: 0.0,


top: top,


child: Row(


mainAxisAlignment: MainAxisAlignment.center,


crossAxisAlignment: CrossAxisAlignment.center,


children: <Widget>[


Expanded(


child: Container(


alignment: Alignment.centerRight,


child: RefreshImage(top),


margin: const EdgeInsets.only(right: 12.0),


),


),


Column(


children: <Widget>[


Text(


text,


style: ts,


),


Text(


'Last updated:' +


DateFormat('yyyy-MM-dd hh:mm').format(time),


style: ts.copyWith(fontSize: 12),


)


],


),


Expanded(


child: Container(),


),


],


),


)


],


),


);


}


}


class RefreshImage extends StatelessWidget {


const RefreshImage(this.top);


final double top;


@override


Widget build(BuildContext context) {


const double imageSize = 40;

用户头像

Android架构

关注

还未添加个人签名 2021.10.31 加入

还未添加个人简介

评论

发布
暂无评论
Flutter自适应瀑布流,深入浅出安卓开发