我正在尝试制作一个具有文本字段的底表,并将自动对焦设置为true,以便弹出键盘。但是,底纸被键盘重叠。有没有办法将底页移到键盘上方?
Padding( padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), child: Column(children: <Widget>[ TextField( autofocus: true, decoration: InputDecoration(hintText: 'Title'), ), TextField( decoration: InputDecoration(hintText: 'Details!'), keyboardType: TextInputType.multiline, maxLines: 4, ), TextField( decoration: InputDecoration(hintText: 'Additional details!'), keyboardType: TextInputType.multiline, maxLines: 4, ),]);
在扑1.7.X和以后 更多的功能已经被添加到BottomSheetDialog这样除了@ anmol.majhail的回答,您可以添加isScrollControlled = true到showModalBottomSheet它会允许底片取足所需的高度给出了更多的保险TextField是不包括在键盘。
BottomSheetDialog
isScrollControlled = true
showModalBottomSheet
TextField
像这样:
showModalBottomSheet( shape: RoundedRectangleBorder( borderRadius: BorderRadius.vertical(top: Radius.circular(25.0))), backgroundColor: Colors.black, context: context, isScrollControlled: true, builder: (context) => Padding( padding: const EdgeInsets.symmetric(horizontal:18 ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: <Widget>[ Padding( padding: const EdgeInsets.symmetric(horizontal: 12.0), child: Text('Enter your address', style: TextStyles.textBody2), ), SizedBox( height: 8.0, ), Padding( padding: EdgeInsets.only( bottom: MediaQuery.of(context).viewInsets.bottom), child: TextField( decoration: InputDecoration( hintText: 'adddrss' ), autofocus: true, controller: _newMediaLinkAddressController, ), ), SizedBox(height: 10), ], ), ));
请注意:
shape: RoundedRectangleBorder( borderRadius: BorderRadius.vertical(top: Radius.circular(25.0))),
不是必需的 只是我正在创建一个圆形的底页。
更新资料
如果你的BottomSheetModel就是Column确保你添加 mainAxisSize: MainAxisSize.min,,否则这个表将覆盖整个屏幕。
BottomSheetModel
Column
mainAxisSize: MainAxisSize.min,