Search
▪️

Running Native Swift, Objective-C, Java, or Kotlin Code

native 기능을 쓰는 것이 아니라 native의 정보를 가져오기 위해서는 native로 message를 보내야 한다.
unique identifier를 준 MethodChannel을 이용한다.
import 'package:flutter/services.dart'
MethodChannel로 native와 소통할 수 있도록 Flutter에서 코드를 만들면, native에서 역시 해당 method를 받을 수 있도록 Channel을 만들어야 한다. (MethodChannel에서 Call을 받을 수 있도록 Handler가 필요하다.)
android는 native code에 library import를 해주고 Battery 상태를 가져오려면 Native에서 BatteryManager을 이용한 Method를 사용한다.
iOS는 native code에 library import를 해주고 controller을 통해서 Method Channel 제어하게 되는데 Battery 상태를 가져오려면 UIDevice의 설정을 통해 가져온다.
<MethodChannel>.invokeMethod() 함수는 생성된 메소드 채널을 통해 메세지를 보내는 역할을 수행한다.
Method 이름을 인자로 보낸다.
arguments도 인자로 보낸다.
invokeMethod로 메세지를 보내는 것은 try catch로 감싸줘야 한다. (catch는 on PlatformException을 catch한다.)