Upgrade to Pro — share decks privately, control downloads, hide ads and more …

비둘기 - 박제창 Flutter Developer Meetup - Seoul

November 10, 2023

비둘기 - 박제창 Flutter Developer Meetup - Seoul

비둘기 - 박제창 Flutter Developer Meetup - Seoul


November 10, 2023

More Decks by JaiChangPark

Other Decks in Programming


  1. 2 Pigeons and papyrus at Amarna: the birds of the

    Green Room revisited Christopher M. Stimpson1,* & Barry J. Kemp2,*
  2. Flutter Multi-Platform Mobile Bring your app idea to more users

    from day one by building with Flutter on iOS and Android simultaneously, without sacrificing features, quality, or performance. Android iOS Web Easily reach more users in browsers with the same experience as on mobile devices through the power of Flutter on the web. Chrome etc.. Desktop & Embedded Build high-quality desktop apps without compromising compatibility or performance. Flutter's support for custom embedders means you can create new ways to put Flutter to work on the platforms that matter to you. Windows macOS Linux 3
  3. Pigeon is a code generator tool to make communication between

    Flutter and the host platform type-safe, easier, and faster. • Pigeon removes the necessity to manage strings across multiple platforms and languages. • It also improves efficiency over common method channel patterns. • Most importantly though, it removes the need to write custom platform channel code, since pigeon generates it for you. Code Generator tool Pigeon 6
  4. Currently pigeon supports generating: • Kotlin and Java code for

    Android • Swift and Objective-C code for iOS and macOS • C++ code for Windows Supported Platforms Pigeon 7
  5. Pigeon Code Generator tool 8 .dart file Flutter App iOS

    Host Android Host Desktop Host Dart Objective-C Swift Java, Kotlin Pigeon 🕊
  6. class MessageData { String? name; Code code; Map<String?, String?> data;

    MessageData({required this.code, required this.data}); } 15 @HostApi() abstract class SimpleHostApi { bool sendMessage(MessageData message); }
  7. dart run pigeon \ --input pigeons/messaging.dart \ --dart_out lib/pigeon.dart \

    --objc_header_out ios/Runner/pigeon.h \ --objc_source_out ios/Runner/pigeon.m \ --java_out ./android/app/src/main/java/com/example/xxxx/Pigeon.java \ --java_package "com.example.xxxx" 17
  8. @ConfigurePigeon(PigeonOptions( dartOut: 'lib/src/messages.g.dart', dartOptions: DartOptions(), cppOptions: CppOptions(namespace: 'pigeon_example'), cppHeaderOut: 'windows/runner/messages.g.h',

    cppSourceOut: 'windows/runner/messages.g.cpp', kotlinOut: 'android/app/src/main/kotlin/com/dreamwalker/flutter_pigeon/Messages.g.kt', kotlinOptions: KotlinOptions(), javaOut: 'android/app/src/main/java/io/flutter/plugins/Messages.java', javaOptions: JavaOptions(), swiftOut: 'ios/Runner/Messages.g.swift', swiftOptions: SwiftOptions(), objcHeaderOut: 'macos/Runner/messages.g.h', objcSourceOut: 'macos/Runner/messages.g.m', objcOptions: ObjcOptions(prefix: 'PGN'), copyrightHeader: 'pigeons/copyright.txt', dartPackageName: 'pigeon_example', )) 18
  9. 20 Future<String> getHostLanguage() async { final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(

    'dev.flutter.pigeon.pigeon_example.SimpleHostApi.getHostLanguage', codec, binaryMessenger: _binaryMessenger); final List<Object?>? replyList = await channel.send(null) as List<Object?>?; if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); } /// else if else { return (replyList[0] as String?)!; } }
  10. 21 class MainActivity : FlutterActivity() { override fun configureFlutterEngine(flutterEngine: FlutterEngine)

    { super.configureFlutterEngine(flutterEngine) val api = PigeonApiImplementation() SimpleHostApi.setUp(flutterEngine.dartExecutor.binaryMessenger, api); } }
  11. 22 @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application(

    _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) let controller = window?.rootViewController as! FlutterViewController let api = PigeonApiImplementation() ExampleHostApiSetup.setUp(binaryMessenger: controller.binaryMessenger, api: api) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } }
  12. 23 private class PigeonApiImplementation: SimpleHostApi { override fun getHostLanguage(): String

    { return "Kotlin" } override fun sendMessage(message: MessageData, callback: (Result<Boolean>) -> Unit) { if (message.code == Code.ONE) { callback(Result.failure(FlutterError("code", "message", "details"))) return } callback(Result.success(true)) } }
  13. 24 private class PigeonApiImplementation: SimpleHostApi { func getHostLanguage() throws ->

    String { return "Swift" } func sendMessage(message: MessageData, completion: @escaping (Result<Bool, Error>) -> Void) { if (message.code == Code.one) { completion(.failure(FlutterError(code: "code", message: "message", details: "details"))) return } completion(.success(true)) } }
  14. 25 ElevatedButton( onPressed: () async { final host = await

    ExampleHostApi().getHostLanguage(); // custom code.. }, child: Text("호스트 정보"), )
  15. • Pigeon is a code generator tool to make communication

    between Flutter and the host platform • type-safe ◦ Kotlin and Java code for Android ◦ Swift and Objective-C code for iOS and macOS ◦ C++ code for Windows Summary Pigeon Code Generator tool 26