简体   繁体   English

InkWell 小部件需要 Material 小部件祖先

[英]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.有两种方法可以解决上述问题。

  1. Replace InkWell with GestureDetectorInkWell替换GestureDetector

     GestureDetector( onTap: () { },);
  2. Wrap InkWell with Material , as InkWell required Material Widget to wrapMaterial包裹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.

相关问题 未找到方向性小部件。 InkWell 小部件需要 Directionality 小部件祖先 - No Directionality widget found. InkWell widgets require a Directionality widget ancestor 未找到材料小部件文本字段小部件需要材料小部件祖先 - No material widget found textfield widgets require a material widget ancestor 未找到材质小部件 文本字段小部件需要材质小部件祖先(颤振) - No Material Widget found textfield widgets require a material widget ancestor(Flutter) Flutter:下拉按钮<bankaccountdto>小部件需要一个 Material 小部件祖先</bankaccountdto> - Flutter: DropdownButton<BankAccountDTO> widgets require a Material widget ancestor Flutter - 临时错误 - IconButton 小部件需要 Material 小部件祖先 - Flutter -Temporary error - IconButton widgets require a Material widget ancestor FlutterError(未找到 Material 小部件。IconButton 小部件需要 Material 小部件祖先 - FlutterError (No Material widget found. IconButton widgets require a Material widget ancestor 找不到方向性小部件。 RichText小部件需要Directionality小部件祖先 - No Directionality widget found. RichText widgets require a Directionality widget ancestor 未找到 MaterialLocalizations - MyApp 小部件需要由 Localizations 小部件祖先提供的 MaterialLocalizations - No MaterialLocalizations found - MyApp widgets require MaterialLocalizations to be provided by a Localizations widget ancestor 未找到 MediaQuery 小部件祖先。 Scaffold 小部件需要 MediaQuery 小部件祖先 - No MediaQuery widget ancestor found. Scaffold widgets require a MediaQuery widget ancestor Flutter:Inkwell 小部件和“支持点击的小部件”的作用 - Flutter: The role of the Inkwell widget and "widgets that support taps"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM