我在一个包装小部件中有4个芯片,芯片的数量是根据答案长度来确定的,因为这是答案的长度,所以我需要为芯片创建一个背景色,而不是为每个芯片创建一个背景色,现在我已经创建了芯片并根据长度显示,芯片列表是垂直的,所以对于第一个芯片,第二个颜色(0xFFFFFFB139),第三色(0xFFFFFFB139),第三色(0xFFFFFFFFFFFFFFFFD)。
这是芯片的代码
child: Chip(
backgroundColor: Colors.blue, // hardcoded color
label: Container(
width: 80.w,
height: 11.3.h,
child: Align(
alignment: Alignment.topCenter,
child: Text(
answersText,
style: GoogleFonts.fredokaOne(
textStyle: TextStyle(
fontSize: 20.0.sp,
color: Colors.white),
),
textAlign: TextAlign.center,
),
),
),
)发布于 2022-10-18 06:13:47
Wrap(
direction: Axis.horizontal,
children: List.generate(widget.targetSet.length, (index) => Container(
height: 50,
width: ((MediaQuery.of(context).size.width-100)/4),
decoration: BoxDecoration(
color: darken(Color.red,(index*0.1),
border: Border.all(width: 1,color: Color.green),
),
)
)
),在创建Wrap时使用上述代码。
Color darken(Color color, [double amount = .1]) {
assert(amount >= 0 && amount <= 1);
final hsl = HSLColor.fromColor(color);
final hslDark = hsl.withLightness((hsl.lightness - amount).clamp(0.0, 1.0));
return hslDark.toColor();
}https://stackoverflow.com/questions/70347658
复制相似问题