flutter - 键盘显示时脚手架不再调整大小
问题描述
当我单击输入字段并显示键盘时,在我的应用程序中使用以下代码应打印文本“此处”。当我在现有应用程序中使用此代码时,它不起作用。didChangeMetrics
不叫。在新的独立应用程序中使用它时,它可以工作。有谁知道这可能是什么原因?我比较了 AndroidManifest.xml 文件,它们都包含:
<application
android:name=".Application"
android:label="Framr"
android:icon="@mipmap/launcher_icon"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
我能看到的唯一区别是我必须重新注册一个 firebaseio.flutter.app.FlutterApplication
插件.Application
。
这是小部件的代码:
class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeMetrics() {
print("Here");
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text("test"),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 40),
Align(
alignment: Alignment.center,
child: FlatButton(
child: CircleAvatar(
radius: 40.0,
backgroundColor: Colors.grey,
),
onPressed: () {},
)),
SizedBox(height: 40),
Text('Name'),
TextFormField(
textAlign: TextAlign.left,
),
SizedBox(height: 140),
Text('Bio'),
TextFormField(
textAlign: TextAlign.left,
maxLength: 150,
),
SizedBox(height: 20),
])),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Increment',
child: Icon(Icons.add),
)
);
}
}
解决方案
推荐阅读
- powershell - Sovled:Powershell - 如何将参数存储到变量并使用它?
- c++ - C++ 新手,使用模板函数时出现编译器错误
- jquery - 如何将服务注入jquery函数
- excel - 匹配 ID 的 Excel 合并
- javascript - AADSTS90014:请求正文必须包含以下参数:“client_id”
- php - Google Analytics API v3 > analytics.management.uploads.uploadData 权限不足问题
- python - 只接受一种文件类型
- php - 自引用表与交叉引用表的关联映射
- touch - GSL1680-电容式触摸屏控制器
- oracle - Oracle Apex 5.1:页面项目的拆分值