text
stringlengths
1
474
whose windowBackground is set to the
Drawable that should be displayed as the launch screen.In addition, styles.xml defines a normal theme
to be applied to FlutterActivity after the launch
screen is gone. The normal theme background only shows
for a very brief moment after the splash screen disappears,
and during orientation change and Activity restoration.
Therefore, it’s recommended that the normal theme use a
solid background color that looks similar to the primary
background color of the Flutter UI.<topic_end>
<topic_start>
Set up the FlutterActivity in AndroidManifest.xml
In AndroidManifest.xml, set the theme of
FlutterActivity to the launch theme. Then,
add a metadata element to the desired FlutterActivity
to instruct Flutter to switch from the launch theme
to the normal theme at the appropriate time.The Android app now displays the desired launch screen
while the app initializes.<topic_end>
<topic_start>
Android 12
To configure your launch screen on Android 12,
check out Android Splash Screens.As of Android 12, you must use the new splash screen
API in your styles.xml file.
Consider creating an alternate resource file for Android 12 and higher.
Also make sure that your background image is in line with
the icon guidelines;
check out Android Splash Screens for more details.Make sure that
io.flutter.embedding.android.SplashScreenDrawable is
not set in your manifest, and that provideSplashScreen
is not implemented, as these APIs are deprecated.
Doing so causes the Android launch screen to fade smoothly
into the Flutter when the
app is launched and the app might crash.Some apps might want to continue showing the last frame of
the Android launch screen in Flutter. For example,
this preserves the illusion of a single frame
while additional loading continues in Dart.
To achieve this, the following
Android APIs might be helpful:
<code_start>import android.os.Build;
import android.os.Bundle;
import android.window.SplashScreenView;
import androidx.core.view.WindowCompat;
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// Aligns the Flutter view vertically with the window.
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// Disable the Android splash screen fade out animation to avoid
// a flicker before the similar frame is drawn in Flutter.
getSplashScreen()
.setOnExitAnimationListener(
(SplashScreenView splashScreenView) -> {
splashScreenView.remove();
});
}
super.onCreate(savedInstanceState);
}
}<code_end>
<code_start>import android.os.Build
import android.os.Bundle
import androidx.core.view.WindowCompat
import io.flutter.embedding.android.FlutterActivity
class MainActivity : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// Aligns the Flutter view vertically with the window.
WindowCompat.setDecorFitsSystemWindows(getWindow(), false)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// Disable the Android splash screen fade out animation to avoid
// a flicker before the similar frame is drawn in Flutter.
splashScreen.setOnExitAnimationListener { splashScreenView -> splashScreenView.remove() }
}
super.onCreate(savedInstanceState)
}
}<code_end>
Then, you can reimplement the first frame in Flutter
that shows elements of your Android launch screen in
the same positions on screen.
For an example of this, check out the
Android splash screen sample app.
<topic_end>
<topic_start>Binding to native Android code using dart:ffi
Flutter mobile and desktop apps can use the
dart:ffi library to call native C APIs.
FFI stands for foreign function interface.
Other terms for similar functionality include
native interface and language bindings.info Note
This page describes using the dart:ffi library
in Android apps. For information on iOS, see
Binding to native iOS code using dart:ffi.
For information in macOS, see
Binding to native macOS code using dart:ffi.
This feature is not yet supported for web plugins.Before your library or program can use the FFI library
to bind to native code, you must ensure that the
native code is loaded and its symbols are visible to Dart.
This page focuses on compiling, packaging,
and loading Android native code within a Flutter plugin or app.This tutorial demonstrates how to bundle C/C++
sources in a Flutter plugin and bind to them using
the Dart FFI library on both Android and iOS.
In this walkthrough, you’ll create a C function