移动App开发 Flutter 设置 Container 内阴影

 Flutter 内阴影效果展示,我想达到的是如下效果:

 

这个其实是两个Container 组合出来的,外层Container纯背景要看的边框阴影的颜色,里面一层白色的:

大家可以参考下面的代码,也可以设置对应的颜色:

import 'package:app_customer/src/utils/screen_utils.dart';
import 'package:flutter/material.dart';

class TestOne extends StatefulWidget {
  const TestOne({Key? key}) : super(key: key);

  @override
  State<TestOne> createState() => _TestOneState();
}

class _TestOneState extends State<TestOne> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          height: ScreenUtils.height(300),
          width: ScreenUtils.height(600),
          padding: EdgeInsets.only(top: 30, left: 10, right: 10),
          child: Container(
            padding: EdgeInsets.all(10),
            child: Container(
              decoration: BoxDecoration(
                // color: Colors.grey,
                color: Color(0x759A4105),
                borderRadius: BorderRadius.all(
                  Radius.circular(12),
                ),
              ),
              padding: EdgeInsets.all(10),
              child: Container(
                padding: EdgeInsets.zero,
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.all(Radius.circular(8)),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.white,
                      blurRadius: 10,
                      spreadRadius: 10,
                    ),
                  ],
                ),
                width: double.infinity,
                height: 272,
                child: Center(
                  child: Text("内部阴影效果"),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

注意点:如果背景色跟阴影色相近或者相同的话,需要设置阴影样式

BoxShadow(
  color: Color(0xFFFFECDC),
  // 注意点 设置的阴影样式
  blurStyle: BlurStyle.inner,
  blurRadius: ScreenUtils.width(20),
  spreadRadius: ScreenUtils.width(25),
),

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

低头确望水中月亮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值