Skip to content

[pigeon] enums parameters do not work with the dartHostTestHandler #105742

Closed
flutter/packages
#2749

Description

@gaaclarke

When using:

enum StorageDirectory {
  music,
  podcasts,
  ringtones,
  alarms,
  notifications,
  pictures,
  movies,
  downloads,
  dcim,
  documents,
}

@HostApi(dartHostTestHandler: 'TestPathProviderApi')
abstract class PathProviderApi {
  List<String?> getExternalStoragePaths(StorageDirectory directory);
}

Pigeon will generate a dart file like:

  Future<List<String?>> getExternalStoragePaths(StorageDirectory arg_directory) async {
    final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
        'dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths', codec, binaryMessenger: _binaryMessenger);
    final Map<Object?, Object?>? replyMap =
        await channel.send(<Object?>[arg_directory.index]) as Map<Object?, Object?>?;
    ...
  }

And a test file like:

        channel.setMockMessageHandler((Object? message) async {
          assert(message != null, 'Argument for dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths was null.');
          final List<Object?> args = (message as List<Object?>?)!;
          final StorageDirectory? arg_directory = (args[0] as StorageDirectory?);
          assert(arg_directory != null, 'Argument for dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths was null, expected non-null StorageDirectory.');
          final List<String?> output = api.getExternalStoragePaths(arg_directory!);
          return <Object?, Object?>{'result': output};
        });

Which causes an int to be cast as a StorageDirectory?: type 'int' is not a subtype of type 'StorageDirectory?' in type cast

I guess it makes sense to make the test generator take in an int which it transforms to a StorageDirectory in this case.

Activity

  1. added
    P2Important issues not at the top of the work list
    on Jun 21, 2022
  2. github-actions commented on Nov 14, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  3. locked as resolved and limited conversation to collaborators on Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2Important issues not at the top of the work listp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions