Я недавно начал изучать флаттер и разрабатывать мобильные приложения. Я хочу создать стартовый экран с минимальной анимацией (например, поворот изображения). Из документации здесь я подумал, что это можно сделать, используя метод, упомянутый в разделе «Создание пользовательского SplashScreen». Но я понятия не имею, с чего начать. Сначала я создал проект flutter java, используя
flutter create -a java custom_spla sh
Затем я попытался скопировать код, указанный в ссылке на документацию внутри MainActivity. java файл и запустить приложение, но приложение просто не удалось собрать. Я также пытался использовать рисование поворота внутри launch_background. xml, хотя оно поворачивало изображение на определенный угол, оно было * stati c и не анимировано.
Примечание: Я не создал ни одного нативного android приложения, и java также является новым для меня
РЕДАКТИРОВАТЬ 1: Я думаю, Я должен отобразить это как представление вместо рисования. Я попробовал это. Создан файл с именем SplashScreenWithTransition. java рядом с MainActivity. java
package com.example.native_splash;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.native_splash.mySplashView;
import io.flutter.embedding.android.SplashScreen;
public class SplashScreenWithTransition implements SplashScreen {
@Override
@Nullable
public View createSplashView(
@NonNull Context context,
@Nullable Bundle savedInstanceState
) {
// Return a new MySplashView without saving a reference, because it
// has no state that needs to be tracked or controlled.
return new mySplashView(context);
}
@Override
public void transitionToFlutter(@NonNull Runnable onTransitionComplete) {
// Immediately invoke onTransitionComplete because this SplashScreen
// doesn't display a transition animation.
//
// Every SplashScreen *MUST* invoke onTransitionComplete at some point
// for the splash system to work correctly.
onTransitionComplete.run();
}
}
и другой файл с именем mySplashView. java
package com.example.native_splash;
import android.content.Context;
public class mySplashView extends android.view.View {
public mySplashView(Context context) {
super(context);
}
}
и представлением. xml внутри папки для рисования
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="vertical">
<rotate
android:fromDegrees="0"
android:toDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:drawable="@mipmap/ic_launcher"/>
</LinearLayout>
Изменены стили. xml следующим образом
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowFullscreen">true</item>
</style>
<style name="ViewTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/view</item>
</style>
</resources>
Наконец изменен AndroidManifest. xml следующим образом
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.native_splash">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="native_splash"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="com.example.native_splash.SplashScreenWithTransition"
android:resource="@style/ViewTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
Сейчас когда я запускаю его с помощью F5, приложение строит и запускает, но не отображает содержимое в представлении. xml хотя на экране запуска действительно отображается LaunchTheme.
Возможно ли иметь простые анимации на экране запуска во флаттере приложение? если так, что я делаю не так?