我有一个设计任务,在图中的图像。我需要创建一个小部件相同的图像。
颜色可以从最后一行移到顶部。
此外,它还兼容多种屏幕尺寸。
class ThermometerWidget extends StatelessWidget {
const ThermometerWidget({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
width: 100,
height: 300,
decoration: const BoxDecoration(
color: Colors.white,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(Radius.circular(16)),
boxShadow: [
BoxShadow(
color: Color(0xFFBFC9D7),
offset: Offset(4, 4),
blurRadius: 10,
)
]),
child: Stack(
children: [
Container(
width: 14,
height: 4,
margin: const EdgeInsets.only(top: 30),
decoration: const BoxDecoration(
color: Color(0xFFB0B0B0),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topRight: Radius.circular(16),
bottomRight: Radius.circular(16),
),
),
),
Container(
width: 14,
height: 4,
margin: const EdgeInsets.only(top: 60),
decoration: const BoxDecoration(
color: Color(0xFFB0B0B0),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topRight: Radius.circular(16),
bottomRight: Radius.circular(16),
),
),
),
Container(
width: 14,
height: 4,
margin: const EdgeInsets.only(top: 90),
decoration: const BoxDecoration(
color: Color(0xFFB0B0B0),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topRight: Radius.circular(16),
bottomRight: Radius.circular(16),
),
),
),
Container(
width: 14,
height: 4,
margin: const EdgeInsets.only(top: 120),
decoration: const BoxDecoration(
color: Color(0xFFB0B0B0),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topRight: Radius.circular(16),
bottomRight: Radius.circular(16),
),
),
),
Container(
width: 14,
height: 4,
margin: const EdgeInsets.only(top: 150),
decoration: const BoxDecoration(
color: Color(0xFFB0B0B0),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topRight: Radius.circular(16),
bottomRight: Radius.circular(16),
),
),
),
Align(
alignment: Alignment.topRight,
child: Container(
width: 14,
height: 4,
margin: const EdgeInsets.only(top: 38),
decoration: const BoxDecoration(
color: Color(0xFFB0B0B0),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16),
bottomLeft: Radius.circular(16),
),
),
),
),
Align(
alignment: Alignment.topRight,
child: Container(
width: 14,
height: 4,
margin: const EdgeInsets.only(top: 68),
decoration: const BoxDecoration(
color: Color(0xFFB0B0B0),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16),
bottomLeft: Radius.circular(16),
),
),
),
),
Align(
alignment: Alignment.topRight,
child: Container(
width: 14,
height: 4,
margin: const EdgeInsets.only(top: 98),
decoration: const BoxDecoration(
color: Color(0xFFB0B0B0),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16),
bottomLeft: Radius.circular(16),
),
),
),
),
Align(
alignment: Alignment.topRight,
child: Container(
width: 14,
height: 4,
margin: const EdgeInsets.only(top: 128),
decoration: const BoxDecoration(
color: Color(0xFFB0B0B0),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16),
bottomLeft: Radius.circular(16),
),
),
),
),
Align(
alignment: Alignment.topRight,
child: Container(
width: 14,
height: 4,
margin: const EdgeInsets.only(top: 158),
decoration: const BoxDecoration(
color: Color(0xFFB0B0B0),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16),
bottomLeft: Radius.circular(16),
),
),
),
),
Align(
alignment: Alignment.center,
child: Stack(
alignment: Alignment.topCenter,
children: [
Container(
width: 80,
margin: const EdgeInsets.only(top: 160),
decoration: const BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Color(0xFFBFC9D7),
blurRadius: 10,
offset: Offset(2, 3),
)
],
),
),
Container(
width: 40,
height: 200,
margin: const EdgeInsets.only(top: 20),
decoration: const BoxDecoration(
color: Colors.white,
shape: BoxShape.rectangle,
boxShadow: [
BoxShadow(
color: Color(0xFFBFC9D7),
blurRadius: 10,
offset: Offset(2, 3),
)
],
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
),
),
Container(
width: 60,
margin: const EdgeInsets.only(top: 160),
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
),
Container(
width: 30,
height: 160,
margin: const EdgeInsets.only(top: 80),
decoration: const BoxDecoration(
color: Color(0xFFF5F5F5),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16),
),
),
),
Container(
width: 60,
margin: const EdgeInsets.only(top: 160),
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Color(0xFFF5F5F5),
),
),
],
),
)
],
),
);
}
}
这里我的代码。我的代码也设置硬大小。如何优化它的多个屏幕大小和正确的设计。
请帮帮我谢谢你的帮助
1条答案
按热度按时间vwkv1x7d1#
你可以只使用
CustomPaint
小部件就可以做到这一点,但是我让它更“动态”一点,我使用了一个自定义的ImplicitlyAnimatedWidget
,现在如果你用不同的参数重建Thermo
小部件,你可以看到它如何动画value
(和/或color
)属性。你可以用这个
ThermoTest
小部件来测试它:这就是结果
编辑
自定义的
OutlinedBorder
似乎比自定义的CustomPainter
类更好:你可以用以下方法测试它:
结果是: