如何在 flutter 中禁用 Inkwell 图像按钮
How to disable Inkwell image button in flutter
我想禁用墨水瓶图像按钮。我可以禁用 onTap
事件,但不能使灰色像禁用按钮一样。我尝试添加此代码
decoration: new BoxDecoration(color:Colors.grey.withOpacity(0.6)),
但它并没有如我所愿。
我的代码:
child: Container(
decoration:
new BoxDecoration(color: Colors.grey.withOpacity(0.6)),
child: Material(
//elevation: 4.0,
clipBehavior: Clip.none,
color: Colors.black,
child: Stack(
alignment: Alignment.center,
fit: StackFit.passthrough,
children: [
Ink.image(
image: AssetImage(ihaveheard_imagepath),
fit: BoxFit.cover,
width: MediaQuery.of(context).size.width / 4 * 3,
height: MediaQuery.of(context).size.width / 6,
child: InkWell(onTap: () {}),
),
Align(
alignment: Alignment.center,
child: Padding(
padding: EdgeInsets.all(8.0),
child: InkWell(
child: Text(
LocaleKeys.ihaveheard,
style: TextStyle(
fontSize:
MediaQuery.of(context).size.width / 30,
color: Colors.white),
).tr(),
onTap: () {
ihaveheard_imagepath =
"assets/images/greenbutton.png";
setState(() {});
},
),
),
)
],
),
),
),
您可以使用 IgnorePointer
作为父窗口小部件来防止标签事件。
IgnorePointer(
ignoring: disableBtn, //true, false
child: yourWidget()
您可以将 null 传递给 decoration
以显示基于可点击状态的默认值
Container(
decoration: disableBtn? BoxDecoration(...): null,
.....
)
child:
IgnorePointer(
ignoring: disableBtn, //true or false
child: Container(
foregroundDecoration: disableBtn
? BoxDecoration( //this can make disabled effect
color: Colors.grey,
backgroundBlendMode: BlendMode.lighten)
: null,
child: ...
我想禁用墨水瓶图像按钮。我可以禁用 onTap
事件,但不能使灰色像禁用按钮一样。我尝试添加此代码
decoration: new BoxDecoration(color:Colors.grey.withOpacity(0.6)),
但它并没有如我所愿。
我的代码:
child: Container(
decoration:
new BoxDecoration(color: Colors.grey.withOpacity(0.6)),
child: Material(
//elevation: 4.0,
clipBehavior: Clip.none,
color: Colors.black,
child: Stack(
alignment: Alignment.center,
fit: StackFit.passthrough,
children: [
Ink.image(
image: AssetImage(ihaveheard_imagepath),
fit: BoxFit.cover,
width: MediaQuery.of(context).size.width / 4 * 3,
height: MediaQuery.of(context).size.width / 6,
child: InkWell(onTap: () {}),
),
Align(
alignment: Alignment.center,
child: Padding(
padding: EdgeInsets.all(8.0),
child: InkWell(
child: Text(
LocaleKeys.ihaveheard,
style: TextStyle(
fontSize:
MediaQuery.of(context).size.width / 30,
color: Colors.white),
).tr(),
onTap: () {
ihaveheard_imagepath =
"assets/images/greenbutton.png";
setState(() {});
},
),
),
)
],
),
),
),
您可以使用 IgnorePointer
作为父窗口小部件来防止标签事件。
IgnorePointer(
ignoring: disableBtn, //true, false
child: yourWidget()
您可以将 null 传递给 decoration
以显示基于可点击状态的默认值
Container(
decoration: disableBtn? BoxDecoration(...): null,
.....
)
child:
IgnorePointer(
ignoring: disableBtn, //true or false
child: Container(
foregroundDecoration: disableBtn
? BoxDecoration( //this can make disabled effect
color: Colors.grey,
backgroundBlendMode: BlendMode.lighten)
: null,
child: ...