開發環境:Android Studio+flutter插件
1.引入第三方包後需要殺死應用後重新運行,才能真正將第三方包部署上去,不然直接ctrl+s或者點小閃電(熱更新)會導致Unhandled Exception: MissingPluginException(No implementation found for method xxx on channel
2.點擊空白隱藏鍵盤,在根佈局下通過手勢判斷,手指擡起時根佈局獲取焦點從而將輸入框的焦點擠掉,鍵盤也就自動隱藏了
child:GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
// 觸摸收起鍵盤
FocusScope.of(context).requestFocus(FocusNode());
},
child: Container()
)
3.按鈕設置邊距margin和padding之類的可以通過外包一層Container(),在Container中設置margin和padding
padding: EdgeInsetsDirectional.fromSTEB(10, 0, 10, 0), //左,上,右,下,順時針
margin: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 10), //左,上,右,下,順時針
4.彈Toast 使用 FlutterToast
5.onPressed的小坑:原本想通過自定義一個VoidCallback類,將其賦值給onPressed從而將onPressed中的方法抽出來放到該類中,結果發現onPressed所在的widge的頁面退出和進入該頁面時也會調用VoidCallback類中的代碼,同時點擊的時候也會調用:
...
onPressed: showToast()
...
VoidCallback showToast(){
Fluttertoast.showToast(
msg: "hello",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.black,
textColor: Colors.white,
fontSize: 16.0
);
}
應該改爲這樣,纔是所想要的點擊一次調用一次的效果:
onPressed: (){
showToast();
}
void showToast(){
Fluttertoast.showToast(
msg: "hello",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.black,
textColor: Colors.white,
fontSize: 16.0
);
}
先記錄,多了再重新整理