Slide 1

Slide 1 text

비둘기 박제창 (@Dreamwalker) 1

Slide 2

Slide 2 text

2 Pigeons and papyrus at Amarna: the birds of the Green Room revisited Christopher M. Stimpson1,* & Barry J. Kemp2,*

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Platform integration Flutter Communication with host 4 @source: https://medium.com/flutter/flutter-platform-channels-ce7f540a104e

Slide 5

Slide 5 text

type-safe? 5

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Pigeon Code Generator tool 8 .dart file Flutter App iOS Host Android Host Desktop Host Dart Objective-C Swift Java, Kotlin Pigeon 🕊

Slide 9

Slide 9 text

9 https://github.com/flutter/packages/blob/main/packages/pigeon/doc/pigeon_state.png

Slide 10

Slide 10 text

10 https://pub.dev/packages/pigeon https://github.com/flutter/packages/tree/main/packages/pige on

Slide 11

Slide 11 text

Flutterfire 11

Slide 12

Slide 12 text

video_player 12

Slide 13

Slide 13 text

Installing Add pigeon as a dev_dependency 13

Slide 14

Slide 14 text

@HostApi() abstract class SimpleHostApi { String getHostLanguage(); } 14

Slide 15

Slide 15 text

class MessageData { String? name; Code code; Map data; MessageData({required this.code, required this.data}); } 15 @HostApi() abstract class SimpleHostApi { bool sendMessage(MessageData message); }

Slide 16

Slide 16 text

Pigeon @HostApi Flutter에서 호스트 플랫폼을 호출하고 싶을때 사용 @FlutterApi 호스트 플랫폼에서 Flutter 앱을 호출하고 싶을때 사용 16

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

@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

Slide 19

Slide 19 text

dart run pigeon --input ./pigeons/message.dart 19

Slide 20

Slide 20 text

20 Future getHostLanguage() async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.pigeon_example.SimpleHostApi.getHostLanguage', codec, binaryMessenger: _binaryMessenger); final List? replyList = await channel.send(null) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); } /// else if else { return (replyList[0] as String?)!; } }

Slide 21

Slide 21 text

21 class MainActivity : FlutterActivity() { override fun configureFlutterEngine(flutterEngine: FlutterEngine) { super.configureFlutterEngine(flutterEngine) val api = PigeonApiImplementation() SimpleHostApi.setUp(flutterEngine.dartExecutor.binaryMessenger, api); } }

Slide 22

Slide 22 text

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) } }

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

24 private class PigeonApiImplementation: SimpleHostApi { func getHostLanguage() throws -> String { return "Swift" } func sendMessage(message: MessageData, completion: @escaping (Result) -> Void) { if (message.code == Code.one) { completion(.failure(FlutterError(code: "code", message: "message", details: "details"))) return } completion(.success(true)) } }

Slide 25

Slide 25 text

25 ElevatedButton( onPressed: () async { final host = await ExampleHostApi().getHostLanguage(); // custom code.. }, child: Text("호스트 정보"), )

Slide 26

Slide 26 text

● 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

Slide 27

Slide 27 text

THANK YOU! 27