Flutter module run in android native FlutterActivity공부방/Flutter2023. 10. 16. 17:39
Table of Contents
Flutter module을 Android Native FlutterActivity 화면에서
바로 띄우려면 아래 코드처럼 작성 하고 띄우면 된다.
package com.strongbulb.myapplication
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.strongbulb.myapplication.databinding.ActivityMainBinding
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterActivityLaunchConfigs
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.FlutterEngineCache
import io.flutter.embedding.engine.dart.DartExecutor
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugins.GeneratedPluginRegistrant
private const val FLUTTER_ENGINE_NAME1 = "custom1"
class MainActivity : FlutterActivity() {
private val channelName = "com.example.host/start" // 메소드 채널 이름(모듈과 같아야 함)
private var channel1 : MethodChannel? = null
private lateinit var binding: ActivityMainBinding
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
flutterEngine.navigationChannel.setInitialRoute("start")
flutterEngine.dartExecutor.executeDartEntrypoint(
DartExecutor.DartEntrypoint.createDefault()
)
// FlutterEngine을 등록하기 위해 Dart 코드 실행
channel1 = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channelName)
// 메소드채널 위치 설정
FlutterEngineCache
.getInstance()
.put(FLUTTER_ENGINE_NAME1, flutterEngine)
GeneratedPluginRegistrant.registerWith(flutterEngine);
channel1?.invokeMethod("param", "{" +
"}")
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
}
반응형
'공부방 > Flutter' 카테고리의 다른 글
@soycrab :: 꿀맛코딩
행복한 코딩을 위하여!
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!