首页 > 解决方案 > 键盘显示时脚手架不再调整大小

问题描述

当我单击输入字段并显示键盘时,在我的应用程序中使用以下代码应打印文本“此处”。当我在现有应用程序中使用此代码时,它不起作用。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),
        )
    );
  }
}

标签: flutter

解决方案


推荐阅读