diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 0125754716..ca42319af1 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.2 + +* Added support for enums. + ## 0.2.1 * Java: Fixed issue where multiple async HostApis can generate multiple Result interfaces. diff --git a/packages/pigeon/README.md b/packages/pigeon/README.md index 5283dc0404..4292c03160 100644 --- a/packages/pigeon/README.md +++ b/packages/pigeon/README.md @@ -70,7 +70,9 @@ Nested data-types are supported, too. Note: Generics for List and Map aren't supported yet. -## Asynchronous Handlers +## Features + +### Asynchronous Handlers By default Pigeon will generate synchronous handlers for messages. If you want to be able to respond to a message asynchronously you can use the `@async` @@ -112,7 +114,7 @@ public interface Api2Host { } ``` -## Null Safety (NNBD) +### Null Safety (NNBD) Right now Pigeon supports generating null-safe code, but it doesn't yet support [non-null fields](https://github.com/flutter/flutter/issues/59118). @@ -121,6 +123,57 @@ The default is to generate null-safe code but in order to generate non-null-safe code run Pigeon with the extra argument `--no-dart_null_safety`. For example: `flutter pub run pigeon --input ./pigeons/messages.dart --no-dart_null_safety --dart_out stdout`. +### Enums + +As of version 0.2.2 Pigeon supports enum generation. For example: +```dart +enum State { + pending, + success, + error, +} + +class StateResult { + String? errorMessage; + State? state; +} + +@HostApi() +abstract class Api { + StateResult queryState(); +} +``` + +Generates on Dart, Java, Objective-C: +```dart +enum State { + pending, + success, + error, +} +``` + +```java +public enum State { + pending(0), + success(1), + error(2); + + private int index; + private State(final int index) { + this.index = index; + } +} +``` + +```objc +typedef NS_ENUM(NSUInteger, State) { + StatePending = 0, + StateSuccess = 1, + StateError = 2, +}; +``` + ## Feedback File an issue in [flutter/flutter](https://github.com/flutter/flutter) with the diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 25c06b750f..f9bdc210f2 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -8,7 +8,7 @@ import 'dart:mirrors'; import 'ast.dart'; /// The current version of pigeon. This must match the version in pubspec.yaml. -const String pigeonVersion = '0.2.1'; +const String pigeonVersion = '0.2.2'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index c442d4c2ae..ce8c6af715 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/master/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon -version: 0.2.1 # This must match the version in lib/generator_tools.dart +version: 0.2.2 # This must match the version in lib/generator_tools.dart environment: sdk: '>=2.12.0 <3.0.0'