[英]How to Change the splash color when tapping DropdownButton In flutter?
[英]Prevent keyboard dismiss when tapping DropdownButton
這個問題與顫振有關。 我在 TextField 上方有一個 DropdownButton,如下所示:
DropdownButton<String>(
isExpanded: true,
hint: Text(associatedHint),
disabledHint: Text(associatedHint),
items: diagnosesList.map((int value) {
return DropdownMenuItem<String>(
value: value.toString(),
child: Text(dxDisplay),
);
}).toList(),
value: ANID,
onChanged: (String newANID) {
setState(() {
ANID = newANID;
});
},
),
TextField(
autofocus: true,
keyboardType: keyboardType,
maxLines: maxLines,
textCapitalization: TextCapitalization.sentences,
controller: _textEntryController,
decoration: InputDecoration(hintText: "Entry"),
onChanged: (value) {
noteEntry = value;
},
),
TextField 自動對焦立即調出鍵盤。 當您點擊 DropdownButton 時,它會從 TextField 中移除焦點,從而關閉鍵盤。 這會在屏幕上移動內容並創建糟糕的用戶體驗。
有關如何解決此問題的任何建議? 即使在點擊 DropdownButton 后,有沒有辦法讓鍵盤保持打開狀態?
終於找到了解決辦法。 需要將 AlertDialog 包裝在 SingleChildScrollView 中。 這會在屏幕頂部打開 AlertDialog,並且在鍵盤打開/關閉時不會移動它。 它還確保如果內容太長(垂直),它可以在鍵盤下滑動,用戶可以使用滾動手勢查看隱藏內容/與隱藏內容交互。
return SingleChildScrollView(
child: AlertDialog(
title: alertTitle,
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget> [
DropdownButton<String>(
.......
),
TextField(
autofocus: true,
.......
),
],
),
)
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.