flutter - Flutter:导航回同一屏幕后键盘自动打开
问题描述
我有一个屏幕,其中有一个文本字段。如果我点击文本字段然后关闭键盘,然后我使用导航到其他屏幕Navigator
,然后导航回该屏幕,即使自动对焦设置为 false,键盘也会自动弹出
文本字段代码,
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.sdpWidth),
color: themeManager.themeMode == ThemeMode.dark
? Colors.white10
: Colors.white,
border: Border.all(color: Colors.grey)),
margin: EdgeInsets.symmetric(horizontal: 16.sdpWidth),
width: MediaQuery.of(context).size.width * 0.9,
child: TextFormField(
controller: textController,
obscureText: false,
onChanged: (text) async {
store.orgPlantList.clear();
await store.getOrgPlantList(
isLoading: true,
searchText: text,
lat: store.lat,
long: store.long);
if (text.isEmpty) {
store.orgPlantList.clear();
await store.getOrgPlantList(
isLoading: true,
searchText: text,
lat: store.lat,
long: store.long);
}
},
autofocus: false,//<<<<<<<<<<<<<<<<<<< autoFocus is turned off
decoration: InputDecoration(
prefixIcon: Icon(
Icons.search,
color: FlutterFlowTheme.tertiaryColor,
),
hintText: langText().searchPointOfInterest,
hintStyle: FlutterFlowTheme.bodyText1.override(
fontFamily: 'Playfair Display',
fontSize: 18.sdpHeight,
color: themeManager.themeMode == ThemeMode.dark
? Colors.white70
: FlutterFlowTheme.tertiaryColor,
),
suffixIcon: InkWell(
onTap: () async {
if (textController.text.isNotEmpty) {
textController.clear();
store.orgPlantList.clear();
await store.getOrgPlantList(
isLoading: true,
searchText: '',
lat: store.lat,
long: store.long);
}
},
child: Icon(
Icons.cancel,
color: FlutterFlowTheme.tertiaryColor,
),
),
),
style: FlutterFlowTheme.bodyText1.override(
fontFamily: 'Playfair Display',
fontSize: 18.sdpWidth,
),
),
),
导航功能,
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NavBarPage(
initialPage: 'HomePage',
orgPlantId: store.orgPlantList[index].id,
),
),
),
我在下一个字段中没有任何其他文本字段,所以我该如何解决这个问题
解决方案
在导航到其他屏幕之前尝试添加以下代码。它将删除当前的键盘焦点。
FocusManager.instance.primaryFocus.unfocus();
推荐阅读
- notepad++ - 如何防止 Notepad++ 更改 Autohotkey 注释的字体样式
- python - 如何在python中使用json文件可视化图像
- python - 如何从 Django rest 框架中基于类的视图中获取一些过滤结果?
- flutter - 谷歌地图打破抽屉
- java - @Value 在我的 springboot 项目中不起作用
- javascript - 为什么“包裹”不起作用,而“包裹捆绑器”却起作用?
- excel - Excel - 如何获得相应的数量?
- npm - 将 npm-shrinkwrap 的 lockfileVersion 永久修复为 lockfileVersion@1,它会自动生成 lockfileversion@2?
- .net - SignalR 适用于本地 IIS 但不适用于生产服务器,无法识别 Websocket
- javascript - VIEW_CHANNEL 权限有问题