top: marginTb, left: marginLr, right: marginLr, bottom: marginTb),

decoration: BoxDecoration(//边框颜色+圆角

color: Colors.white,

borderRadius: BorderRadius.all(

Radius.circular(ViewUtils.currentWidth(40.0)),

),

),

),

);

}

流式布局wrap每一项布局样式+圆角背景(BoxDecoration,borderRadius)+文本(Text)+点击事件( GestureDetector\onTap)

@override

Widget build(BuildContext context) {

double marginLr = ViewUtils.currentWidth(50.0);

double marginTb = ViewUtils.currentHeight(300.0);

return Container(

color: Color(0x80000000),

child: Container(

padding: EdgeInsets.only(

left: ViewUtils.currentWidth(48.0),

right: ViewUtils.currentWidth(48.0)),

margin: EdgeInsets.only(

top: marginTb, left: marginLr, right: marginLr, bottom: marginTb),

child: Column(

crossAxisAlignment: CrossAxisAlignment.start,

children: [

_label(context),

Container(

padding: EdgeInsets.only(

bottom: ViewUtils.currentHeight(30.0),

top: ViewUtils.currentHeight(30.0)),

child: Text(

“颜色”,

style: TextStyle(

fontSize: 22.0,

color: Color(0xFF6D7278),

decoration: TextDecoration.none),

),

),

Wrap(

spacing: ViewUtils.currentWidth(20.0),

runSpacing: ViewUtils.currentHeight(20.0),

children: _widgets(this),

),

],

),

decoration: BoxDecoration(

color: Colors.white,

borderRadius: BorderRadius.all(

Radius.circular(ViewUtils.currentWidth(40.0)),

),

),

),

);

}

List colors = [“银色”, “金色”, “深空灰”, “暗夜绿”];

List colorCheck = [true, false, false, false];

Widget _colorLvItem(index) {

Radius radius = Radius.circular(ViewUtils.currentHeight(40.0));

return GestureDetector(

onTap: () {

setState(() {

for (int i = 0; i < colorCheck.length; i++) {

colorCheck[i] = (i == index);

}

ViewUtils.toast(context,colors[index]);

});

},

child: Container(

padding: EdgeInsets.only(

top: ViewUtils.currentHeight(10.0),

bottom: ViewUtils.currentHeight(10.0),

left: ViewUtils.currentWidth(44.0),

right: ViewUtils.currentWidth(44.0)),

decoration: new BoxDecoration(

color: Color(colorCheck[index] ? 0xFFFFCA59 : 0x4F1E1E1E),

borderRadius: BorderRadius.all(radius),

),

child: Text(

colors[index],

style: TextStyle(

color: Color(0xFFffffff),

fontSize: 16.0,

decoration: TextDecoration.none),

),

),

);

}

List _widgets(State state) {

return colors.asMap().keys.map((index) => _colorLvItem(index)).toList();

}

GestureDetector+onTap()+setState()缺一不可:

如果没有setState,我们就无法去动态修改颜色数组的值:

若取消setState,效果如何呢?

我们点击其他标签切换颜色的时候没有颜色变化了。

setState(){}的调用时吧视图重新绘制了一遍,所以为了完成重新绘制,你懂的。

总结:不管在新的技术或者看似很简单的技术面前,我们不要去退缩,要跟好的完成每一个细节,也许离成功就不远了。

参考:

流式布局 Wrap:https://book.flutterchina.club/chapter4/wrap_and_flow.html?h=wrap

最后

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助

因此我收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门**

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐