text stringlengths 1 372 |
|---|
the process for including native code in source |
code or binary form is the same for an app or |
plugin. |
<topic_end> |
<topic_start> |
open-source third-party |
follow the add c and c++ code to your project |
instructions in the android docs to |
add native code and support for the native |
code toolchain (either CMake or ndk-build). |
<topic_end> |
<topic_start> |
closed-source third-party library |
to create a flutter plugin that includes dart |
source code, but distribute the C/C++ library |
in binary form, use the following instructions: |
<topic_end> |
<topic_start> |
android APK size (shared object compression) |
android guidelines in general recommend |
distributing native shared objects uncompressed |
because that actually saves on device space. |
shared objects can be directly loaded from the APK |
instead of unpacking them on device into a |
temporary location and then loading. |
APKs are additionally packed in transit—that’s |
why you should be looking at download size. |
flutter APKs by default don’t follow these guidelines |
and compress libflutter.so and libapp.so—this |
leads to smaller APK size but larger on device size. |
shared objects from third parties can change this default |
setting with android:extractNativeLibs="true" in their |
AndroidManifest.xml and stop the compression of libflutter.so, |
libapp.so, and any user-added shared objects. |
to re-enable compression, override the setting in |
your_app_name/android/app/src/main/AndroidManifest.xml |
in the following way. |
<topic_end> |
<topic_start> |
other resources |
to learn more about c interoperability, check out these videos: |
<topic_end> |
<topic_start> |
hosting native android views in your flutter app with platform views |
platform views allow you to embed native views in a flutter app, |
so you can apply transforms, clips, and opacity to the native view |
from dart. |
this allows you, for example, to use the native |
google maps from the android SDK |
directly inside your flutter app. |
info note |
this page discusses how to host your own native android views |
within a flutter app. |
if you’d like to embed native iOS views in your flutter app, |
see hosting native iOS views. |
flutter supports two modes: |
hybrid composition and virtual displays. |
which one to use depends on the use case. |
let’s take a look: |
hybrid composition |
appends the native android.view.View to the view hierarchy. |
therefore, keyboard handling, and accessibility work out of the box. |
prior to android 10, this mode might significantly |
reduce the frame throughput (fps) of the flutter UI. |
for more context, see performance. |
virtual displays |
render the android.view.View instance to a texture, |
so it’s not embedded within the android activity’s view hierarchy. |
certain platform interactions such as keyboard handling |
and accessibility features might not work. |
to create a platform view on android, |
use the following steps: |
<topic_end> |
<topic_start> |
on the dart side |
on the dart side, create a widget |
and add one of the following build implementations. |
<topic_end> |
<topic_start> |
hybrid composition |
in your dart file, |
for example native_view_example.dart, |
use the following instructions: |
add the following imports: |
<code_start> |
import 'package:flutter/foundation.dart'; |
import 'package:flutter/gestures.dart'; |
import 'package:flutter/material.dart'; |
import 'package:flutter/rendering.dart'; |
import 'package:flutter/services.dart'; |
<code_end> |
implement a build() method: |
<code_start> |
widget build(BuildContext context) { |
// this is used in the platform side to register the view. |
const string viewType = '<platform-view-type>'; |
// pass parameters to the platform side. |
const Map<String, dynamic> creationParams = <string, dynamic>{}; |
return PlatformViewLink( |
viewType: viewType, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.