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

最后

感谢您的阅读,在文末给大家准备一个福利。本人从事Android开发已经有十余年,算是一名资深的移动开发架构师了吧。根据我的观察发现,对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长且无助。

所以在此将我十年载,从萌新小白一步步成长为Android移动开发架构师的学习笔记,从Android四大组件到手写实现一个架构设计,我都有一一的对应笔记为你讲解。

当然我也为你们整理好了百度、阿里、腾讯、字节跳动等等互联网超级大厂的历年面试真题集锦。这也是我这些年来养成的习惯,一定要学会把好的东西,归纳整理,然后系统的消化吸收,这样才能极大的提高学习效率和成长进阶。碎片、零散化的东西,我觉得最没有价值的。就好比你给我一张扑克牌,我只会觉得它是一张废纸,但如果你给我一副扑克牌,它便有了它的价值。这和我们收集资料就要收集那些系统化的,是一个道理。

最后,赠与大家一句诗,共勉!

不驰于空想,不骛于虚声。不忘初心,方得始终。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!
的。就好比你给我一张扑克牌,我只会觉得它是一张废纸,但如果你给我一副扑克牌,它便有了它的价值。这和我们收集资料就要收集那些系统化的,是一个道理。

[外链图片转存中…(img-xvXsYbkK-1714961291347)]

最后,赠与大家一句诗,共勉!

不驰于空想,不骛于虚声。不忘初心,方得始终。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!

Logo

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

更多推荐