[英]InkWell widgets require a Material widget ancestor
I am adding InkWell in Row as Widget but it is throwing me an error:我在 Row 中添加 InkWell 作为小部件,但它给我一个错误:
flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building InkWell(gestures: [tap], clipped to BoxShape.rectangle,
flutter: dirty, state: _InkResponseState<InkResponse>#0e6c5):
flutter: No Material widget found.
flutter: InkWell widgets require a Material widget ancestor.
Here is my code:这是我的代码:
Container(
color: Colors.red,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
InkWell(
onTap: (){
//Forgot password Tapped
},
child: Text(Constants.forgotPassword),),
],
),
InkWell
Class will always work with a Material Class InkWell
类将始终与材料类一起使用
Please try the code below.请尝试下面的代码。
Code: Wrap the InkWell Class with the Material Class代码:用材质类包裹 InkWell 类
Material(
child: InkWell(
onTap: (){
//Forgot password Tapped
},
child: Text(Constants.forgotPassword),),
),
Thanks谢谢
用 Scaffold 包裹 InkWell 类,那么问题就会消失。
There are two ways to resolve the above issue.有两种方法可以解决上述问题。
Replace InkWell
with GestureDetector
用
InkWell
替换GestureDetector
GestureDetector( onTap: () { },);
Wrap InkWell
with Material
, as InkWell
required Material
Widget to wrap用
Material
包裹InkWell
,因为InkWell
需要Material
Widget 来包裹
InkWell( onTap: () { },);
Note: To introduce a Material widget, you can either directly include one, or use a widget that contains Material itself, such as a Card, Dialog, Drawer, or Scaffold.注意:要引入 Material 小部件,您可以直接包含一个小部件,也可以使用包含 Material 本身的小部件,例如Card、Dialog、Drawer 或 Scaffold。
It is not said that the Material
should be added as father.并不是说应该将
Material
添加为父亲。
If it is a StatelessWidget
and you pushed to go to this page , he automatically expects it to be the parent of the widget, such as a Scaffold
for example.如果它是一个
StatelessWidget
并且您推送到此页面,他会自动期望它是小部件的父级,例如Scaffold
。
It happened to me too, in the end many of the components in Flutter already extend Material
, so the problem may be sooner.我也遇到过,最后Flutter中很多组件都已经扩展了
Material
,所以问题可能会更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.