Can't assign method to onPressed from Dao delete method

77 Views Asked by At

Error:

The argument type 'void Function()' can't be assigned to the parameter type 'void Function(BuildContext)?'.

Code

  return Slidable(
    endActionPane: ActionPane(
      motion: ScrollMotion(),
      children: <Widget>[
        SlidableAction(
          label: 'Delete',
          foregroundColor: Colors.white,
          backgroundColor: Colors.red,
          icon: Icons.delete,
          onPressed: () => database.deleteGoal(itemGoal),
        ),
      ],

    ),

function form moore_database.dart

  Future deleteGoal(Goal goal) => delete(goals).delete(goal);

How should I approach this problem I have read that I should change method for VoidCallback, but what is correct solution with defining in good manner database methods.

1

There are 1 best solutions below

0
behnam bagvand On

Instead of,

onPressed: () => database.deleteGoal(itemGoal),

Put the context.

onPressed: (context) => database.deleteGoal(itemGoal),