錯誤日誌
Another exception was thrown: 'package:flutter/src/rendering/viewport.dart': Failed assertion: line 662 pos 12: 'child.parent == this': is not true.
場景(已知)
類型1
我們在使用自定義dialog的時候,佈局中有使用TextField TextFormField 當他們獲取到了焦點,彈出軟盤時,會拋出該異常。
類型2
我們在使用自定義dialog的時候,佈局中有使用 多包含類型佈局 如 ListView GridView 他們嵌套了TextField TextFormField 當他們獲取到了焦點,彈出軟盤時,會拋出該異常。
解決方案
包裹一層ScrollView 推薦使用簡單的 SingleChildScrollView
僞代碼
new SingleChildScrollView(
child: TextField(
// keyboardType: TextInputType.multiline,
// controller: accountController,
textAlign: TextAlign.center,
// autofocus: true, //自動獲取焦點
// maxLength: 7,
style: new TextStyle(fontSize: 14.0, color: Colors.black),
maxLines: 1,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(2.0),
border: OutlineInputBorder(),
hintText: betItems[index].rate,
suffix: new ImageIcon(
new AssetImage("images/ic_edit_note.png"),
color: null,
size: 10.0)),
onChanged: (String value) {
betItems[index].rate = value;
},
),
))