golubets 1.0.0+3
golubets: ^1.0.0+3 copied to clipboard
Code generator tool to make communication between Flutter and the host platform type-safe and easier.
Enhanced Flutter Platform Communication
The modern, feature-rich alternative to Pigeon that just works better.
Golubets is a powerful code generator for type-safe communication between Flutter and native platforms. Built as a community-driven fork of Pigeon, it delivers the advanced features developers have been asking for, with a smoother development experience.
β¨ Why Choose Golubets? #
π― Enhanced Features #
- Default Parameters - Cleaner APIs with optional parameters (Swift & Kotlin)
- True Async Support - Modern Swift concurrency & Kotlin coroutines
- Generics - Type-safe collections like
List<T>,Map<K, V> - Advanced Sealed classes - Swift enums, Kotlin nested types
- Rock Solid - All the reliability of Pigeon, with bugs fixed
π€ Developer Experience #
- Community-First - Your feedback shapes our roadmap
- Quick Onboarding - Get running in minutes, not hours
- Clear Documentation - Examples that actually work
- Responsive Support - Issues get attention, not ignored
π Feature Highlights #
| Feature | Golubets | Pigeon |
|---|---|---|
| Default Parameters | β | β |
| Swift Async/Await | β | β |
| Kotlin Coroutines | β | β |
| Generics Support | β | β |
| Kotlin Nested Sealed Classes | β | β |
| Swift enums | β | β |
| Community Contributions | β Welcome! | π Challenging |
π Quick Start #
Get up and running with Golubets in under 5 minutes:
# 1. Add to your Flutter project
flutter pub add --dev golubets
# 2. Create your API definition (e.g., golubtsi/api.dart)
# 3. Generate platform code
dart run golubets --input golubtsi/api.dart
# 4. Implement the generated interfaces in your native code
# 5. Start using type-safe platform communication!
π Want to see it in action? Check out our complete example with working iOS, Android, and desktop implementations.
π The Golubets Difference #
While Pigeon pioneered type-safe Flutter platform communication, the ecosystem has evolved. Developers need modern language features, faster iteration cycles, and responsive community support.
Golubets delivers exactly that:
- Modern Language Support - Embrace Swift concurrency, Kotlin coroutines, and generics
- Faster Development - Default parameters reduce boilerplate
- Community-Driven - Features are prioritized based on real developer needs
- Contributor-Friendly - Clear guidelines, helpful reviews, and welcoming maintainers
We believe great tools should empower developers, not frustrate them. Golubets is built on the solid foundation of Pigeon while addressing the gaps that matter most to modern Flutter development.
π― Our Mission #
Building the Flutter platform communication tool developers actually want to be part of.
- π§ Community First - Your feedback directly shapes our roadmap. Real issues get real solutions.
- β‘ Smooth Contributions - PRs are collaborative conversations, not battles. Get helpful reviews, not gatekeeping.
- π Innovation Welcome - Bold ideas and fresh perspectives drive us forward. Let's build something amazing together.
- π Full Transparency - Open decisions, clear documentation, and honest communication. Always.
π€ Join the Community #
Ready to contribute? We'd love to have you aboard!
Quick Contribution Guide
- π Browse open issues or create your own
- π¬ Discuss your approach - we're here to help plan it out
- π¨ Submit your PR with clear descriptions and tests
- β Get constructive feedback - we're rooting for your success!
Ways to Help
- π Fix bugs - Every bug squashed makes Golubets better
- β¨ Add features - Implement those missing pieces developers need
- π Improve docs - Help others discover and use Golubets effectively
- π£οΈ Share feedback - Tell us what's working and what could be better
Got a game-changing idea? Don't hesitate to start a discussion - we're excited to explore new possibilities!
π οΈ Comprehensive Platform Support #
One API definition, native code for every platform.
π± Mobile & Desktop Ready #
- π€ Android - Kotlin & Java with modern language features
- π iOS/macOS - Swift & Objective-C with async/await support
- πͺ Windows - Native C++ integration
- π§ Linux - GObject bindings
π― Rich Type System #
Express complex data structures with confidence.
- π€ All Standard Types - Strings, numbers, booleans, lists, maps - full Flutter codec support
- ποΈ Custom Classes - Define your own data types with automatic serialization
- π Enums & Sealed Classes - Type-safe state management (Swift/Kotlin)
- π Generics -
List<T>,Map<K, V>- fully type-safe collections - β Nullability - Proper null safety across all platforms
- 𧬠Inheritance - Sealed parent classes for polymorphic APIs
Pro Tips:
- Use
@SwiftClassfor Objective-C interop when needed - Nullable enums automatically wrapped for Objective-C compatibility
β‘ Modern Async Support #
Choose the concurrency model that fits your platform.
- π Synchronous Methods - Simple, straightforward APIs for immediate responses
- π Callback-Based - Traditional async with
@asyncannotation - π Modern Concurrency - Swift async/await and Kotlin coroutines with
@Async - β οΈ Error Handling - Configurable exception throwing with
isSwiftThrows
// Choose your async style
@HostApi()
abstract class MyApi {
String syncMethod(); // Immediate response
@async
void callbackMethod(); // Traditional callbacks
@Async(type: AsyncType.await(isSwiftThrows: false))
Future<String> modernMethod(); // Swift async and Kotlin coroutines
}
Error Handling #
Kotlin, Java and Swift
All Host API exceptions are translated into Flutter PlatformException.
- For synchronous methods, thrown exceptions will be caught and translated.
- For asynchronous methods, there is no default exception handling; errors should be returned via the provided callback.
To pass custom details into PlatformException for error handling,
use FlutterError in your Host API. Example.
For swift, use GolubetsError instead of FlutterError when throwing an error. See Example#Swift for more details.
Objective-C and C++
Host API errors can be sent using the provided FlutterError class (translated into PlatformException).
For synchronous methods:
- Objective-C - Set the
errorargument to aFlutterErrorreference. - C++ - Return a
FlutterError.
For async methods:
- Return a
FlutterErrorthrough the provided callback.
βοΈ Advanced Features #
Enterprise-grade capabilities for complex applications.
π§΅ Task Queue Support
Control threading behavior with the TaskQueue annotation for specifying threading model:
@HostApi()
abstract class BackgroundApi {
@TaskQueue(type: TaskQueueType.serialBackgroundThread)
@Async(type: AsyncType.await())
void doStuffAtBackground();
}
π Multi-Instance APIs
Create multiple API instances with unique channels for independent operations:
final api1 = MyApi(messageChannelSuffix: 'instance1');
final api2 = MyApi(messageChannelSuffix: 'instance2');
// Both operate independently!
ποΈ Default Parameters (Swift & Kotlin) #
Cleaner APIs with sensible defaults - just like native code should be.
dart:
class UserPreferences {
const UserPreferences({
required this.userId,
this.theme = 'light', // Generated with default in Swift/Kotlin
this.notifications = true, // No more verbose constructors!
this.language = 'en',
});
final String userId;
final String theme;
final bool notifications;
final String language;
}
swift:
public struct UserPreferences: Hashable {
public init(
userId: String,
theme: String = "light",
notifications: Bool = true,
language: String = "en"
) {
self.userId = userId
self.theme = theme
self.notifications = notifications
self.language = language
}
let userId: String
let theme: String
let notifications: Bool
let language: String
}
kotlin:
data class UserPreferences (
val userId: String,
val theme: String = "light",
val notifications: Boolean = true,
val language: String = "en"
)
Benefits:
- π Less Boilerplate - Fewer required parameters in native calls
- π― Better APIs - More intuitive, optional parameters where they make sense
- π Full Type Support - Works with primitives, enums, objects, and collections
π§© Generics (Swift & Kotlin) #
Type-safe collections that actually work across platforms.
sealed class SomeResult<R, E> {
const SomeResult();
}
class Success<R, E> extends SomeResult<R, E> {
const Success(this.value);
final R value;
}
class Error<R, E> extends SomeResult<R, E> {
const Error(this.error);
final E error;
}
@HostApi()
abstract class ExampleHostApi {
SomeResult<List<int>, String> generateNumbers();
}
Supported:
- β
List<T>,Map<K, V>- Basic collections - β
List<Map<K, V>>- Complex nested structures - β
Map<K?, List<V?>>- Nullable generics
Usage #
- Add golubets as a
dev_dependency. - Make a ".dart" file outside of your "lib" directory for defining the communication interface.
- Run golubets on your ".dart" file to generate the required Dart and
host-language code:
flutter pub getthendart run golubetswith suitable arguments. Example. - Add the generated Dart code to
./libfor compilation. - Implement the host-language code and add it to your build (see below).
- Call the generated Dart methods.
Rules for defining your communication interface #
- The file should contain no method or function definitions, only declarations.
- Custom classes used by APIs are defined as classes with fields of the supported datatypes (see the supported Datatypes section).
- APIs should be defined as an
abstract classwith either@HostApi()or@FlutterApi()as metadata.@HostApi()being for procedures that are defined on the host platform and the@FlutterApi()for procedures that are defined in Dart. - Method declarations on the API classes should have arguments and a return
value whose types are defined in the file, are supported datatypes, or are
void. - Event channels are supported only on the Swift, Kotlin, and Dart generators.
- Event channel methods should be wrapped in an
abstract classwith the metadata@EventChannelApi. - Event channel definitions should not include the
Streamreturn type, just the type that is being streamed. - Objective-C and Swift have special naming conventions that can be utilized with the
@ObjCSelectorand@SwiftFunctionrespectively.
Flutter calling into iOS steps #
- Add the generated Objective-C or Swift code to your Xcode project for compilation
(e.g.
ios/Runner.xcworkspaceor.podspec). - Implement the generated protocol for handling the calls on iOS, set it up as the handler for the messages.
Flutter calling into Android Steps #
- Add the generated Java or Kotlin code to your
./android/app/src/main/javadirectory for compilation. - Implement the generated Java or Kotlin interface for handling the calls on Android, set it up as the handler for the messages.
Flutter calling into Windows Steps #
- Add the generated C++ code to your
./windowsdirectory for compilation, and to yourwindows/CMakeLists.txtfile. - Implement the generated C++ abstract class for handling the calls on Windows, set it up as the handler for the messages.
Flutter calling into macOS steps #
- Add the generated Objective-C or Swift code to your Xcode project for compilation
(e.g.
macos/Runner.xcworkspaceor.podspec). - Implement the generated protocol for handling the calls on macOS, set it up as the handler for the messages.
Flutter calling into Linux steps #
- Add the generated GObject code to your
./linuxdirectory for compilation, and to yourlinux/CMakeLists.txtfile. - Implement the generated protocol for handling the calls on Linux, set it up as the vtable for the API object.
Calling into Flutter from the host platform #
Golubets also supports calling in the opposite direction. The steps are similar
but reversed. For more information look at the annotation @FlutterApi() which
denotes APIs that live in Flutter but are invoked from the host platform.
Example.
Stability of generated code #
Golubets is intended to replace direct use of method channels in the internal implementation of plugins and applications. Because the expected use of Golubets is as an internal implementation detail, its development strongly favors improvements to generated code over consistency with previous generated code, so breaking changes in generated code are common.
As a result, using Golubets-generated code in public APIs is strongy discouraged, as doing so will likely create situations where you are unable to update to a new version of Golubets without causing breaking changes for your clients.
Inter-version compatibility #
The generated message channel code used for Golubets communication is an internal implementation detail of Golubets that is subject to change without warning, and changes to the communication are not considered breaking changes. Both sides of the communication (the Dart code and the host-language code) must be generated with the same version of Golubets. Using code generated with different versions has undefined behavior, including potentially crashing the application.
This means that Golubets-generated code should not be split across packages. For example, putting the generated Dart code in a platform interface package and the generated host-language code in a platform implementation package is very likely to cause crashes for some plugin clients after updates.
