Search code examples
fluttergenericsparametersparameter-passingtypedef

Flutter/Dart: The argument type 'bool Function(MyStateNotifier)' can't be assigned to the parameter type 'dynamic Function(dynamic)'


I have a such class declaration in Dart, but when using it the compiler reports error

typedef ContextConditionFilter<T, bool> = bool Function(T);

class ContextStateWidget<T extends StateNotifier> extends StatefulWidget
{
    final Widget child;
    final ContextConditionFilter<T, bool> filter;
    const ContextStateWidget({Key key, @required this.child, @required this.filter}) : super(key: key);
}

A class inherited StateNotifier

class MyStateNotifier extends StateNotifier<DrawMenuState>
{
...
bool get myValue => return true;
}

Using it

ContextStateWidget<MyStateNotifier>(
    filter: ((MyStateNotifier notifier) => notifier.myValue), // error here
    child: const OtherWidget()
);

Error

The argument type 'bool Function(MyStateNotifier)' can't be assigned to the parameter type 'dynamic Function(dynamic)'

Solution

  • Thank aligator for your reply, but actually it's analyzer problem. After restart VSCode, the problem gone :-)