flutter - 颤动中的透明文本字段
问题描述
我正在尝试实现透明TextField
(我正在复制 instagram 故事编辑器 UI)。但是,我得到了一个背景颜色为白色的 TextField。如何删除白色背景并使其TextField
透明?
这是我的代码:
@override
Widget build(BuildContext context) {
return Stack(
children: [
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: widget.onTap,
child: Container(
color: Colors.black.withOpacity(0.5),
),
),
Center(
child: Material(
child: Container(
color: Colors.transparent,
child: TextField(
focusNode: myFocusNode,
cursorColor: Colors.blueAccent,
decoration: InputDecoration(
fillColor: Colors.transparent,
filled: true,
border: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 15,
bottom: 11,
top: 11,
right: 15,
),
),
),
),
),
)
更新:
删除Material
小部件和Container
小部件并Scaffold
在顶部添加解决了问题❤️
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
body: Stack(
children: [
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: widget.onTap,
child: Container(
color: Colors.black.withOpacity(0.5),
),
),
Center(
child: TextField(
focusNode: myFocusNode,
cursorColor: Colors.blueAccent,
decoration: InputDecoration(
fillColor: Colors.transparent,
filled: true,
border: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 15,
bottom: 11,
top: 11,
right: 15,
),
),
),
)
],
),
);
}
解决方案
使Material
透明(你也不需要Container
):
https://www.dartpad.dev/5c0168a92f89ab40b809d2e92c5d51c6?null_safety=true
Center(
child: Material(
color: Colors.transparent,
child: TextField(
cursorColor: Colors.blueAccent,
decoration: InputDecoration(
fillColor: Colors.transparent,
filled: true,
border: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 15,
bottom: 11,
top: 11,
right: 15,
),
),
),
),
);
推荐阅读
- sql-server - 如何根据sql server中的条件获取标志值
- mysql - 关于 node.js 和 mysql
- java - SpringBoot – 在 Rest 方法中添加 Cache Control Headers
- laravel - 如何在laravel单元测试中上传带有json post请求的文件
- java - 不同圆上两点之间的最大和最小距离是多少?
- html - 带箭头的 Bootstrap 手风琴问题
- rxjs - 可从数组轮询服务器观察到
- android - 删除数据库内容后 searchView 不起作用
- mysql - 如何在mysql中使用拆分功能或将拆分值存储在不同的列中?
- php - 具有单引号 (') 值的 JSON 无法存储在隐藏的输入字段中