Flutter学习笔记 边框

本文深入解析Flutter中的BoxDecoration装饰器,展示如何通过该组件实现颜色、边框、圆角、阴影及渐变效果,帮助开发者掌握美化Widget的技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

BoxDecoration(装饰器)

const BoxDecoration({
  this.color,
  this.image,
  this.border,
  this.borderRadius,
  this.boxShadow,
  this.gradient,
  this.backgroundBlendMode,
  this.shape = BoxShape.rectangle,
})

例:

在这里插入图片描述

      body: Center(
        child: Container(
          height: 100.0,
          width: 100.0,
//          color: Colors.pinkAccent,   //会跟decoration里的Color冲突
          decoration: BoxDecoration(
            color: Colors.blue,
            border: Border.all(
              color: Colors.yellow,
              width: 5.0,
              style: BorderStyle.solid,
            ),
            borderRadius: BorderRadius.circular(20.0),
            //圆角
            boxShadow: [
              BoxShadow(
                offset: Offset(5.0, 5.0), //偏移
                color: Colors.grey,
                blurRadius: 10.0, //阴影的模糊
                spreadRadius: 10.0, //阴影的扩散
              ),
            ],
            //shape: BoxShape.rectangle,    //形状,注意与borderRadius冲突
            gradient:
                //镜像渐变
//            RadialGradient(colors: [
//              Color.fromRGBO(7, 102, 255, 1.0),
//              Color.fromRGBO(3, 28, 128, 1.0)
//            ]),
                //线性渐变
                LinearGradient(
              colors: [
                Color.fromRGBO(7, 102, 255, 1.0),
                Color.fromRGBO(3, 28, 128, 1.0)
              ],
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
            ),
          ),
        ),
      ),
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值