首页 > 解决方案 > 选择 Tex Field flutter 时的输入警告

问题描述

我正在玩一个颤振的应用程序,我有一个 TextField。但是,当我单击 TextField 时,键盘显示并且一切运行正常,但我收到了一堆警告/通知。以下是警告:

W/IInputConnectionWrapper(26234): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(26234): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(26234): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper(26234): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(26234): endBatchEdit on inactive InputConnection

飞镖代码:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyWidget extends StatefulWidget{
  @override
  _MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget>{
  bool _isClicked = false;
  int _clickCounter = 0;
  String _inputText;
  final controller = TextEditingController();
  @override
  void dispose() {
    // Clean up the controller when the widget is disposed.
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context){
    return Column(children: [
      TextField(
        controller: controller,
        onSubmitted: (String text) {
          setState(() {
            _inputText = text;
          });
        },
        decoration: InputDecoration(
          hintText: "Whatever you want.",
        )
      ),
      Row(children: [
        ElevatedButton(
          child: Text("Show input"),
          onPressed: (){
            setState(() {
              _inputText = controller.text;
            });
            
          },
        ),
        Text("Your input: $_inputText")
        ],
        mainAxisAlignment: MainAxisAlignment.center,
      ),
      
      InteractiveViewer(child: 
        Image(
        image: _isClicked ? AssetImage("images/download1.jpg") : AssetImage("images/download.jpg"),
        )
      ),
      Row(children: [
        IconButton(
          icon: _isClicked ? Icon(Icons.favorite) : Icon(Icons.favorite_outline),
          color: Colors.blue,
          // on pressed for icons
          onPressed: (){ 
            setState(() {
              if(_isClicked){
                _isClicked = false;
              } else {
                _isClicked = true;
              }
            });
          }
        ),
        Text(_isClicked ? "Favourited" : "Unfavourited"),
      ],
      mainAxisAlignment: MainAxisAlignment.center,
      ),
      Text("This button was clickded $_clickCounter times."),
      Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          RaisedButton(
            child: Text("Click"),
            color: Colors.green[400],
            // on pressed for click button
            onPressed: (){ 
              setState(() {
                _clickCounter++;
              });
            },
          ),
          RaisedButton( 
            color: Colors.red,
            child: Text("Reset"),
            // on pressed for reset 
            onPressed: (){
              setState(() {
                _clickCounter = 0;
                _isClicked = false;
              });
            }
          ),
        ]
      ) 
      ],
    );
  }
}
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Button Stuff",
      home: Scaffold(
        appBar: AppBar(
          title: Text("App Bar"),
          actions: [
            Text("Action1")
          ],
        ),
        body: SingleChildScrollView(
          // stateful widget plugin
          child: MyWidget(),
        ),
      )
    );
  }
}

我想知道为什么这些会出现在我的 cmd 中以及如何摆脱它们。任何帮助将非常感激!

标签: flutterdartflutter-layout

解决方案


在颤振版本 1.12.13 + hotfix8 中,您会收到此错误。如果您更新颤振版本,它将被修复。总之版本起源于?更新版本:

- -终端 - -

   flutter --version
   flutter upgrade

在此处输入图像描述


推荐阅读