【发布时间】:2021-04-03 02:56:42
【问题描述】:
我正在尝试实现透明的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,
),
),
),
)
],
),
);
}
【问题讨论】: