1. 調用接口傳入 List 類型不對導致無法獲取到數據
初始化 List 沒有指定類型,調用接口時直接傳入導致無法獲取數據(接口內部需要傳入 List<int>)
原因:
沒有指定類型的 List 是 List<dynamic>,不是 List<int> 類型的,所以接口無法拿到對應數據
解決:
將 List 定義為 List<int>
2. iOS 直接通過 Xcode 打包打開閃退問題
iOS 打包打開直接閃退問題
需要先進入 example 目錄中,執行 `flutter build ios`,然后再使用 Xcode archive 就可以了。
3. SDK 發版后,平臺帶了 Web
需要在 SDK
的 pubspec.yaml
文件中將下面代碼添加進去用來指定平臺
flutter:
plugin:
platforms:
android:
package: com.example.hello
pluginClass: HelloPlugin
ios:
pluginClass: HelloPlugin
參考鏈接:指定版本
4. 切換 tab 后頁面被重新加載
final List<StatefulWidget> vcList = [new ConversationListPage(),new ContactsPage()];
// 記錄當前選中的 tab index
int curIndex = 0;
@override
Widget build(BuildContext context) {
return new Scaffold(
bottomNavigationBar: new BottomNavigationBar(
items: tabbarList,
type: BottomNavigationBarType.fixed,
onTap: (int index) {
setState(() {
curIndex = index;
});
},
currentIndex: curIndex,
),
body: vcList[curIndex],
);
}
body 修改為使用 IndexedStack
@override
Widget build(BuildContext context) {
return new Scaffold(
bottomNavigationBar: new BottomNavigationBar(
items: tabbarList,
type: BottomNavigationBarType.fixed,
onTap: (int index) {
setState(() {
curIndex = index;
});
},
currentIndex: curIndex,
),
// 這里的 body 修改為 IndexedStack 就可以保證切換時頁面不會被重新加載
body: IndexedStack(
index: curIndex,
children: <Widget>[new ConversationListPage(),new ContactsPage()],
),
);
}
5. 進入詳情頁面返回列表頁,列表無法保持滾動狀態,會返回到最上方
ScrollController _scrollController;
// 用于記錄偏移量
double mPosition = 0;
// 添加滾動的監聽
void _addScroolListener() {
_scrollController.addListener(() {
mPosition = _scrollController.position.pixels;
});
}
// 初始化時將 _scrollController 賦值給 ListView 的 controller
Widget _buildConversationListView() {
return new ListView.builder(
scrollDirection: Axis.vertical,
itemCount: conList.length,
// 初始化時將 _scrollController 賦值給 ListView 的 controller
controller: _scrollController,
itemBuilder: (BuildContext context, int index) {
if (conList.length <= 0) {
return WidgetUtil.buildEmptyWidget();
}
return ConversationListItem(
delegate: this, conversation: conList[index]);
},
);
}
// build 時讓 scrollController 偏移到指定位置
@override
Widget build(BuildContext context) {
this._scrollController = ScrollController(initialScrollOffset: mPosition);
_addScroolListener();
return new Scaffold(
appBar: AppBar(
title: Text("IM Test"),
),
key: UniqueKey(),
body: _buildConversationListView(),
);
}
6. textField 設置 text 時,Android 光標在最前方,iOS 光標在最后方
將光標移動到最后方即可
void setText(String textContent) {
if (textContent == null) {
textContent = '';
}
this.textEditingController.text =
this.textEditingController.text + textContent;
// 將光標移動到最后方
this.textEditingController.selection = TextSelection.fromPosition(
TextPosition(offset: textEditingController.text.length));
_refreshUI();
}