protocol/client.dart file giving 'The named parameter 'context' isn't defined.' error

71 Views Asked by At

I'm using Serverpod to set up my Flutter app.

However, one of the files which I haven't touched is giving the following error:

The named parameter 'context' isn't defined.
Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'context'.dartundefined_named_parameter

The error comes from the context: context part from the protocol/client.dart file below:

class Client extends _i1.ServerpodClient {
  Client(
    String host, {
    _i3.SecurityContext? context,
    _i1.AuthenticationKeyManager? authenticationKeyManager,
  }) : super(
          host,
          _i4.Protocol(),
          context: context,
          authenticationKeyManager: authenticationKeyManager,
        ) {
    example = _EndpointExample(this);
  }

  late final _EndpointExample example;

  @override
  Map<String, _i1.EndpointRef> get endpointRefLookup => {'example': example};

  @override
  Map<String, _i1.ModuleEndpointCaller> get moduleLookup => {};
}

I have tried flutter clean and restarting VS code, plus updating my flutter sdk, however with no success.

Any idea what I could do?

1

There are 1 best solutions below

10
On

You're using a version of serverpod_service_client that is not compatible with the latest version of serverpod_client (Looks like you have serverpod_client updated, but serverpod_service_client is still on an older version).

_i1 is an import alias for the serverpod_client package, and as you can see in the new constructor of ServerpodClient, there is no context parameter (most likely replaced by securityContext):

serverpod_client/lib/src/serverpod_client_io.dart, line 21

ServerpodClient(
  super.host,
  super.serializationManager, {
  dynamic securityContext,
  super.authenticationKeyManager,
  super.logFailedCalls,
  super.streamingConnectionTimeout,
  super.connectionTimeout,
}) {
  // ...

And in the latest version of serverpod_service_client the constructor of Client class should be like this:

serverpod_service_client/lib/src/protocol/client.dart, line 234

Client(
  String host, {
  dynamic securityContext,
  _i1.AuthenticationKeyManager? authenticationKeyManager,
  Duration? streamingConnectionTimeout,
  Duration? connectionTimeout,
}) : super(
        host,
        _i14.Protocol(),
        securityContext: securityContext,
        authenticationKeyManager: authenticationKeyManager,
        streamingConnectionTimeout: streamingConnectionTimeout,
        connectionTimeout: connectionTimeout,
      ) {
  insights = EndpointInsights(this);
}

Which differs from the code you posted. So you can fix it by either upgrading serverpod_service_client or downgrading serverpod_client to make both packages compatible.