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

Flutter Package & Plugin Package

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/

operandoOS

April 18, 2018
Tweet

More Decks by operandoOS

Other Decks in Technology

Transcript

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

    • Steam : operandoOS • YouTubeͰήʔϜ഑৴ͯ͠·͢ʂ • https://www.youtube.com/user/opp228
  2. 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/
  3. Dart packages • fluro • The brightest, hippest, coolest router

    for Flutter. • FlutterͷػೳΛ࢖ͬͯΔ͚ͲɺNativeͷػೳ͸ ࢖ͬͯͳ͍ • https://pub.dartlang.org/packages/fluro
  4. 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
  5. Flutter plugins • Flutter teamͰ؅ཧ͞ΕͯΔPluginୡ • https://github.com/flutter/plugins • ͜͜ʹ͋Δͷ͸Plugin packagesͷΈ

    • Native Bridge࣮૷ͷࢀߟʹͳΔίʔυຬࡌͬΆ͍ • FirebaseͷPlugin͕ॆ࣮ͯ͠Δ
  6. 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; } }
  7. 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() } } }
  8. 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) } } }
  9. pubspec.yaml name: advertising_id description: A Flutter plugin to access advertising

    ID. version: 0.9.0 author: Shinobu Okano <[email protected]> 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"
  10. Now & Future [ٕज़ॻయ4৽ץ] - TechBooster • Flutter PluginΛ࡞Δ @sh4869

    • ϘΫ͸ॻ͍ͯͳ͍Ͱ͢… • ͜Εʹ͞Βʹৄ͘͠ॻ͍ͯ͋Δ...͸ͣʂʂ • https://techbookfest.org/event/tbf04/ circle/11690001
  11. 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/