InkWell widgets require a Material widget ancestor

Viewed 8036

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.

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),),
    ],
),
4 Answers

InkWell Class will always work with a Material Class

Please try the code below.

Code: Wrap the InkWell Class with the Material Class

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

Thanks

There are two ways to resolve the above issue.

  1. Replace InkWell with GestureDetector

     GestureDetector(
       onTap: () {
    
     },);
    
  2. Wrap InkWell with Material, as InkWell required Material Widget to wrap

     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.

Wrap the InkWell Class with Scaffold, then the issue will be gone.

It is not said that the Material should be added as father.

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.

It happened to me too, in the end many of the components in Flutter already extend Material, so the problem may be sooner.

Related