@@ -20,6 +20,9 @@ import com.appmattus.certificatetransparency.certificateTransparencyInterceptor
2020import  com.appmattus.certificatetransparency.certificateTransparencyTrustManager 
2121import  com.appmattus.certificatetransparency.installCertificateTransparencyProvider 
2222import  com.datatheorem.android.trustkit.TrustKit 
23+ import  io.flutter.embedding.engine.FlutterEngine 
24+ import  io.flutter.embedding.engine.dart.DartExecutor 
25+ import  io.flutter.plugin.common.MethodChannel 
2326import  kotlinx.coroutines.DelicateCoroutinesApi 
2427import  kotlinx.coroutines.Dispatchers 
2528import  kotlinx.coroutines.GlobalScope 
@@ -49,6 +52,9 @@ const val LETS_ENCRYPT_R3_INTERM_PK_SHA256 = "jQJTbIh0grw0/1TkHSumWb+Fs0Ggogr621
4952@Suppress(" UNUSED_PARAMETER" 
5053@DelicateCoroutinesApi
5154class  MainActivity  : AppCompatActivity () {
55+ 
56+     private  var  flutterEngine:  FlutterEngine ?  =  null 
57+ 
5258    override  fun  onCreate (savedInstanceState :  Bundle ? ) {
5359        super .onCreate(savedInstanceState)
5460        setContentView(R .layout.activity_main)
@@ -62,6 +68,17 @@ class MainActivity : AppCompatActivity() {
6268            - " *.badssl.com" 
6369            + " rsa4096.badssl.com" 
6470        }
71+ 
72+         //  Prepare the flutter engine:
73+         flutterEngine =  FlutterEngine (this )
74+         flutterEngine!! .dartExecutor.executeDartEntrypoint(
75+             DartExecutor .DartEntrypoint .createDefault()
76+         )
77+     }
78+ 
79+     override  fun  onDestroy () {
80+         super .onDestroy()
81+         flutterEngine?.destroy()
6582    }
6683
6784    private  fun  onStart (@IdRes id :  Int ) {
@@ -478,6 +495,29 @@ class MainActivity : AppCompatActivity() {
478495        }
479496    }
480497
498+     fun  sendFlutterRequest (view :  View ) {
499+         onStart(R .id.flutter_request)
500+ 
501+         val  channel =  MethodChannel (flutterEngine!! .dartExecutor.binaryMessenger, " tech.httptoolkit.pinning_demo.flutter_channel" 
502+ 
503+         println (" Calling Dart method from Kotlin..." 
504+         channel.invokeMethod(" sendRequest" " https://ecc384.badssl.com/" object  :  MethodChannel .Result  {
505+             override  fun  success (result :  Any? ) {
506+                 println (" Success from Dart: $result " 
507+                 onSuccess(R .id.flutter_request)
508+             }
509+ 
510+             override  fun  error (errorCode :  String , errorMessage :  String? , errorDetails :  Any? ) {
511+                 println (" Error: $errorCode  - $errorMessage " 
512+                 onError(R .id.flutter_request, errorMessage ? :  " Unknown error" 
513+             }
514+ 
515+             override  fun  notImplemented () {
516+                 println (" Method not implemented on Dart side." 
517+             }
518+         })
519+     }
520+ 
481521    //  Manually pinned at the lowest level: creating a raw TLS connection, disabling all checks,
482522    //  and then directly analysing the certificate that's received after connection, before doing
483523    //  HTTP by just writing & reading raw strings. Not a good idea, but the hardest to unpin!
0 commit comments