Flutter Package & Plugin Package

E77b6a5f919f7366d94f21eee9a014f5?s=47 operandoOS
April 18, 2018

Flutter Package & Plugin Package

Flutter Package & Plugin Package

文字おこし
https://github.com/operando/Notes/tree/master/Flutter_Meetup_Tokyo_1

Flutter Meetup Tokyo #1
https://flutter-jp.connpass.com/event/84436/

E77b6a5f919f7366d94f21eee9a014f5?s=128

operandoOS

April 18, 2018
Tweet

Transcript

  1. Flutter Package 
 &
 Plugin Package Flutter Meetup Tokyo #1

  2. About Me • Dart͕࠷ڧͱݴ͍ଓ͚ͨਓͰ͢ʂ • ϓϩήʔϚʔ໨ࢦͯ͠·͢ʂ • Discord : operandoOS

    • Steam : operandoOS • YouTubeͰήʔϜ഑৴ͯ͠·͢ʂ • https://www.youtube.com/user/opp228
  3. ٕज़ॻయ4Ͱຊग़͠·͢ʂ • ͜͏ͯ͠๻Β͸ɺॻ੶ΛചΔΞϓϦΛ࡞ͬͨ 2.0.1 • ͥͻങ͍ʹདྷͯͶʂ • Flutterશؔ͘܎ͳ͍Ͱ͢ʂ • https://techbookfest.org/event/tbf04/circle/

    14710011
  4. ͜Ε͔Β঺հ͢Δ
 υΩϡϝϯτͷURL͚ͩ
 ֮͑ͯؼ͍ͬͯͩ͘͞ʂʂ
 ͦΕ͕͢΂ͯͰ͢ʂʂ

  5. Package & Plugin document • Using Packages • https://flutter.io/using-packages/ •

    Developing Packages & Plugins • https://flutter.io/developing-packages/ • Platform-specific code • https://flutter.io/platform-channels/
  6. What is a Packages? • Dart͸pubͰύοέʔδ؅ཧ͞ΕͯΔ • FlutterͷύοέʔδΛ୳͢ͱ͜Ζ΋͋Δ • https://pub.dartlang.org/flutter

    • ϥΠϒϥϦͱࢥͬͯ΋Β͏ͱΘ͔Γ΍͍͢
  7. Flutter Package types • FlutterͰ͸Package types͕෼͔ΕͯΔ • Dart packages •

    Plugin packages
  8. Dart packages • DartͰॻ͔ΕͨϥΠϒϥϦ • Flutterݻ༗ͷػೳؚ͕·Ε͍ͯΔ΋ͷ΋͋Δ

  9. Dart packages • fluro • The brightest, hippest, coolest router

    for Flutter. • FlutterͷػೳΛ࢖ͬͯΔ͚ͲɺNativeͷػೳ͸ ࢖ͬͯͳ͍ • https://pub.dartlang.org/packages/fluro
  10. Plugin packages • DartͰॻ͔ΕͨϥΠϒϥϦ • ϓϥοτϑΥʔϜ(iOS/Android)ݻ༗ͷ࣮૷ͱ ૊Έ߹Θͤ • Native BridgeϥΠϒϥϦతͳ

  11. Plugin packages • shared_preferences • Wraps NSUserDefaults (on iOS) and

    SharedPreferences (on Android), providing a persistent store for simple data. • Flutter͔ΒNativeͷػೳɾAPIΛݺͼग़͢ • https://pub.dartlang.org/packages/ shared_preferences
  12. Flutter plugins • Flutter teamͰ؅ཧ͞ΕͯΔPluginୡ • https://github.com/flutter/plugins • ͜͜ʹ͋Δͷ͸Plugin packagesͷΈ

    • Native Bridge࣮૷ͷࢀߟʹͳΔίʔυຬࡌͬΆ͍ • FirebaseͷPlugin͕ॆ࣮ͯ͠Δ
  13. Native Bridgeͷ࢓૊Έ • ͜ͷυΩϡϝϯτಡΜͰ͍ͩ͘͞ʂ • Writing custom platform-specific code with

    platform channels • https://flutter.io/platform-channels/
  14. Developing Plugin Packages • ෳࡶͳ΋ͷ͡Όͳ͚Εͳͬ͘͞ͱ࡞ΕΔ • ֤ϓϥοτϑΥʔϜͷAPI஌ͬͯΔͱָউ • pub΁ͷެ։΋؆୯

  15. Developing Plugin Packages • ࠓ೔ͷਂ໷ʹ࡞ͬͨ • Flutter͔Β֤ϓϥοτϑΥʔϜͷ޿ࠂIDΛऔಘ͢ Δ΍ʔͭʔ • https://pub.dartlang.org/packages/

    advertising_id • https://github.com/operando/advertising_id
  16. Create the plugin packages • IntelliJ or Android Studio͔Β࡞Δͷָ͕

  17. Create the plugin packages • ίϚϯυ͔ΒͰ΋࡞ΕΔ • NativeͷίʔυΛSwiftͱKotlinͰॻ͘ͳΒҎԼ flutter create

    —template=plugin -i swift -a kotlin advertising_id
  18. advertising_id.dart import 'dart:async'; import 'package:flutter/services.dart'; class AdvertisingId { static const

    MethodChannel _channel = const MethodChannel('advertising_id'); static Future<String> get id async { final String id = await _channel.invokeMethod(‘getAdvertisingId’); return id; } }
  19. AdvertisingIdPlugin.kt class AdvertisingIdPlugin(private val registrar: Registrar) : MethodCallHandler { companion

    object { @JvmStatic fun registerWith(registrar: Registrar) { val channel = MethodChannel(registrar.messenger(), "advertising_id") channel.setMethodCallHandler(AdvertisingIdPlugin(registrar)) } } override fun onMethodCall(call: MethodCall, result: Result) { when (call.method) { "getAdvertisingId" -> thread { try { result.success( AdvertisingIdClient.getAdvertisingIdInfo(registrar.context()).id) } catch (e: Exception) { result.success("") } } else -> result.notImplemented() } } }
  20. SwiftAdvertisingIdPlugin.swift public class SwiftAdvertisingIdPlugin: NSObject, FlutterPlugin { public static func

    register(with registrar: FlutterPluginRegistrar) { let channel = FlutterMethodChannel(name: “advertising_id", binaryMessenger: registrar.messenger()) let instance = SwiftAdvertisingIdPlugin() registrar.addMethodCallDelegate(instance, channel: channel) } public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { switch call.method { case "getAdvertisingId": var idfaString: String! let manager = ASIdentifierManager.shared() if manager.isAdvertisingTrackingEnabled { idfaString = manager.advertisingIdentifier.uuidString } else { idfaString = "" } result(idfaString) default: result(nil) } } }
  21. pubspec.yaml name: advertising_id description: A Flutter plugin to access advertising

    ID. version: 0.9.0 author: Shinobu Okano <okanoshinobu8@gmail.com> homepage: https://github.com/operando/advertising_id flutter: plugin: androidPackage: com.os.operando.advertisingid pluginClass: AdvertisingIdPlugin dependencies: flutter: sdk: flutter environment: sdk: ">=1.21.0 <3.0.0" flutter: ">=0.1.4"
  22. Publishing packages • PublishͷίϚϯυ͕༻ҙ͞ΕͯΔ • --dry-runΛ͚ͭͯ໰୊ͳ͍͔֬ೝ flutter packages pub publish

    --dry-run
  23. Publishing packages • μϝͳͱ͜Ζͱ͔਌੾ʹڭ͑ͯ͘ΕΔͷͰ࠷ߴ☺

  24. Publishing packages • pubspec.yamlͷॻ͖ํ͸Pubspec Formatͷ documentΛݟΔͱ਌੾ʹॻ͍ͯ͋Δ • https://www.dartlang.org/tools/pub/ pubspec

  25. Publishing packages • pubʹpublish͢Δ • ͸͡Ίͯpubʹpublish͢Δ͚࣌ͩGoogleͷ ೝূ͕૸Δ flutter packages pub

    publish
  26. ٙ໰ pubʹ͋͛ͨpackageͬͯ ফͤͳ͍ͷ͔ͳʁ

  27. Now & Future [ٕज़ॻయ4৽ץ] - TechBooster • Flutter PluginΛ࡞Δ @sh4869

    • ϘΫ͸ॻ͍ͯͳ͍Ͱ͢… • ͜Εʹ͞Βʹৄ͘͠ॻ͍ͯ͋Δ...͸ͣʂʂ • https://techbookfest.org/event/tbf04/ circle/11690001
  28. Package & Plugin document • Using Packages • https://flutter.io/using-packages/ •

    Developing Packages & Plugins • https://flutter.io/developing-packages/ • Platform-specific code • https://flutter.io/platform-channels/
  29. ·ͱΊ • ύοέʔδ؅ཧ͸pub͕ͪΌΜͱͯ͠ΔͷͰ؆୯ʂ • Plugin Package͸؆୯ʹ࡞ΕΔɾެ։Ͱ͖Δ • ֤ϓϥοτϑΥʔϜͷAPI஌ͬͯΔͱָউ • ͡ΌΜ͡ΌΜPlugin

    Package࡞Δνϟϯεʂ
  30. Thanks!!