Wednesday, 14 October 2020

Transfer Android Implementation to Flutter Application

I have an implementation of a dual-camera activity as an Android Kotlin project. I want to use the same dual-camera in flutter as flutter doesn't have any libraries to for dual-camera functionality.

I have tried doing it with platform channels, but as it turns out the platform channels are just for message-passing between flutter and native platform. I don't just want to pass messages, I want an android project's fragment/activity to include as a flutter widget which I can use wherever I want.

Basically, there is an Android activity, which has some Kotlin code associated with it. I want all of it to be working in flutter and communicate with it, both the XML front-end and the Kotlin backend. I am attaching my xml file here for reference. The code file just populates the xml components.


<?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>



from Transfer Android Implementation to Flutter Application

No comments:

Post a Comment