移动App开发 Flutter 设置 Container 内阴影
温馨提示:
本文最后更新于 2023年07月20日
,已超过 654 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我。
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),
),
正文到此结束
- 本文标签: flutter 前端
- 本文链接: https://www.letcode.cn/article/16
- 版权声明: 本文由Jack.Chen原创发布,转载请遵循《 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权