分享一些我在學習過程中遇到的問題
1.Android啟動白屏
一些配置比較低的手機上運行測試包時會有一個非常久的啟動白屏洪己,當然打成正式包后會極大的縮短這個時間届良,但還是很明顯的。
在安卓原生開發(fā)中我們都需要對apk啟動速度進行優(yōu)化盗誊,這需要從很多方向去考慮时甚,其中有一個就是閃屏圖片隘弊。我們看到的啟動白屏就是沒有修改過的閃屏,在flutter工程的android包里荒适,我們找到AndroidManif.xml文件梨熙,里面的安卓樣式設置是:
<activity
...
android:theme="@style/LaunchTheme"
...
>
這個樣式是在res/values/styles.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>
</style>
</resources>
可以看到這個設置就是在繪制出第一幀前顯示的一個drawable,看看drawable里寫了什么
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
很簡單的一個白色背景刀诬,結(jié)合官方下面給出的注釋咽扇,可以自己添加一個圖片進來。
所以想解決啟動時那個難看的白屏陕壹,只需要在這里加上背景圖作為啟動閃屏背景就行了质欲,如果想做一些動效和炫酷的閃屏過渡效果,大家可以參考一些原生的閃屏優(yōu)化文章帐要。
2.Flutter工程里看安卓代碼各種飄紅
有時候我們需要在安卓包里去修改一些代碼把敞,或者編寫一些方法時往往打開后發(fā)現(xiàn)滿屏的紅色警告,而且還沒有聯(lián)想和提示榨惠,其實只要點擊右上角的
或者在安卓文件上右擊選擇
就會生成一個新的工作空間,你在那邊修改的代碼會自動同步到flutter工程中
3.Text文字下劃線
Text的decoration默認是TextDecoration.none
不知道什么原因盛霎,有時候定義的Text下面會出現(xiàn)兩條黃色的下劃線赠橙,明明沒有設置decoration的樣式,此時要去掉下面的下劃線只需要在style下面的TextStyle增加屬性decoration: TextDecoration.none
4.Flutter中的動畫
..addStatusListener((state) {
print("animationstate:${state}");
if(state == AnimationStatus.completed){
animationController.reverse();
}else if(state == AnimationStatus.dismissed){
animationController.forward();
}
});
animationController.forward();
forward對應completed
reverse對應dismissed
5.組件通信
flutter組件的通信方式有很多種愤炸,比如回調(diào)期揪,eventbus,Notification等规个。
用Notification時要注意dispatch方法中傳的context必須和他監(jiān)聽的context是同一個Widget的凤薛,否則是不會回調(diào)的,可以在監(jiān)聽的組件中賦值給GlobalKey诞仓,然后在發(fā)送的時候傳入key.currentContext缤苫。
GlobalKey會分配一個唯一的key,并且可以通過key.currentContext獲取到這個key的context
以上是學習過程中自己總結(jié)的墅拭,如有錯誤希望指出活玲,在后面的學習中會持續(xù)更新