本文介绍了InkWell 小部件需要一个 Material 小部件祖先的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Row 中将 InkWell 添加为小部件,但它给我一个错误:

I am adding InkWell in Row as Widget but it is throwing me an error:

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.

这是我的代码:

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 将始终与 Material Class 一起使用

InkWell Class will always work with a Material Class

请尝试下面的代码.

代码:用 Material 类包装 InkWell 类

Code: Wrap the InkWell Class with the Material Class

  Material(
          child: InkWell(
      onTap: (){
        //Forgot password Tapped
      },
    child: Text(Constants.forgotPassword),),
  ),

谢谢

这篇关于InkWell 小部件需要一个 Material 小部件祖先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 09:52