我有一个作为 Android Kotlin 项目的双摄像头活动的实现。我想在 flutter 中使用相同的双摄像头,因为 flutter 没有任何用于双摄像头功能的库。
我曾尝试使用平台通道来做这件事,但事实证明平台通道仅用于 Flutter 和本机平台之间的消息传递。我不只是想传递消息,我想要一个 android 项目的片段/活动作为颤振小部件包含在内,我可以在任何我想要的地方使用它。
基本上,有一个 Android 活动,它有一些与之相关的 Kotlin 代码。我希望所有这些都在 Flutter 中工作并与之通信,包括 XML 前端和 Kotlin 后端。我在这里附上我的 xml 文件以供参考。代码文件仅填充 xml 组件。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<SurfaceView
android:id="@+id/surfaceView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.2" />
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="-65dp"
android:layout_weight="1" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxHeight="30dp"
android:src="@drawable/ic_inclinedline"/>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)