dart 为什么在ios上使用vscode中的textformfield而不是xcode中的时,键盘/应用程序会冻结?

r3i60tvu  于 2023-03-21  发布在  iOS
关注(0)|答案(2)|浏览(114)

有这个奇怪的问题,当我点击TextFormField的键盘将冻结或应用程序将崩溃.在IOS的键盘将冻结在Android上,我不能在TextFormField上键入任何内容,我该如何修复它?
如果我从xcode运行相同的代码,textformfield工作正常。

@override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Column(
      children: [
        Container(
          decoration:
              const BoxDecoration(color: Color.fromARGB(255, 231, 133, 36)),
          height: 8.h,
          width: 135.w,
          child: Padding(
            padding: const EdgeInsets.fromLTRB(8, 40, 0, 0),
            child: Row(
              children: [
                ElevatedButton(
                    style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(
                            const Color.fromARGB(255, 62, 84, 122))),
                    onPressed: () {
                      setState(() {
                        _isExpanded = !_isExpanded;
                      });
                    },
                    child: const Text(
                      'Flight Plan',
                      style: TextStyle(color: Colors.white),
                    )),
              ],
            ),
          ),
        ),
        Expanded(
          child: Stack(
            children: [
              Positioned(
                  top: 0,
                  left: 0,
                  // bottom: 0,
                  child: SizedBox(
                    height: 67.h,
                    width: 135.w,
                    //child: flutterMap(context),
                  )),
              Positioned(
                top: -30,
                left: 135,
                child: AnimatedContainer(
                  color: const Color.fromARGB(255, 62, 84, 122),
                  duration: const Duration(milliseconds: 800),
                  curve: Curves.bounceInOut,
                  height: 20.h,
                  width: 100.w,
                  margin: const EdgeInsets.only(top: 30),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: const [
                          IconButton(
                              icon: Icon(Icons.skip_previous), onPressed: null),
                        ],
                      ),
                      Center(
                        child: Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: TextFormField(
                            autofocus: true,
                            onChanged: (value) => setState(() {}),
                            controller: textFieldController,
                            maxLines: 2,
                            style:
                                const TextStyle(decorationColor: Colors.black),
                            decoration: const InputDecoration(
                                filled: true,
                                fillColor: Colors.white,
                                border: OutlineInputBorder(
                                    borderRadius: BorderRadius.all(
                                        Radius.circular(4.0)))),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    ));
  }

这是Flutter医生的结果

Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel stable, 3.7.2, on macOS 12.6.3 21G419 darwin-x64, locale en-US)
    ! Warning: `dart` on your path resolves to /usr/local/Cellar/dart/2.17.6/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/pannam/Documents/flutter. Consider adding
      /Users/pannam/Documents/flutter/bin to the front of your path.
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
    ✗ Unable to find bundled Java version.
[✓] VS Code (version 1.76.1)
[✓] Connected device (4 available)
[✓] HTTP Host Availability

下面是github存储库github的最低配置

iqxoj9l9

iqxoj9l91#

GestureDetector(
  behavior: HitTestBehavior.opaque,
  onTap: () {
    FocusScope.of(context).unfocus(); // Hide the keyboard when tapped outside
  },
  child: SingleChildScrollView(
    child: Center(
      child: Padding(
        padding: const EdgeInsets.all(8),
        child: TextFormField(
          autofocus: true,
          onChanged: (value) => setState(() {}),
          controller: textFieldController,
          maxLines: 2,
          style: const TextStyle(decorationColor: Colors.black),
          decoration: const InputDecoration(
            filled: true,
            fillColor: Colors.white,
            border: OutlineInputBorder(
              borderRadius: BorderRadius.all(Radius.circular(4)),
            ),
          ),
        ),
      ),
    ),
  ),
)
jjjwad0x

jjjwad0x2#

该死!class _MyHomePageState extends State<MyHomePage> { bool _isExpanded = false; TextEditingController textFieldController = TextEditingController(); ... }是分辨率,最初我是在方法内部设置TextEditingController textFieldController = TextEditingController();的,而不是上面所示的

相关问题