getInputedText on inactive InputConnection flutter

问题描述 投票:0回答:1

我有这个怪异的问题,当我尝试在文本字段中输入值时,当我尝试键入键盘时键盘便出现了,我也正在填写我从sharedprefrence获取的用户名,地点,移动电话,并且它正在工作,但是当我尝试输入年龄,身高,体重键盘并在几秒钟内打开时,这是错误消息/警告,我正在颤抖,医生没有问题,

W/IInputConnectionWrapper(23904): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(23904): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 8756): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 8756): endBatchEdit on inactive InputConnection

代码和视图

class RegistrationScreenState extends State<RegistrationScreen> {

 TextEditingController mobile = TextEditingController();
  TextEditingController Username = TextEditingController();
  TextEditingController Place = TextEditingController();
  TextEditingController age = TextEditingController();
  TextEditingController height = TextEditingController();
  TextEditingController weight = TextEditingController();

  void initState() {
    getDetails();

  }

  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery
        .of(context)
        .size;
    return Scaffold(
      appBar: AppBar(
        title: Text("Registration", style: TextStyle(color: Colors.black)),
        backgroundColor: Colors.orange,
      ),
      body: SingleChildScrollView(
        child: Stack(
          children: [
            Column(
              children: [
                Container(
                  child: Image.asset('assets/images/gym.png',
                      height: 150,
                      width: double.infinity,
                      fit: BoxFit.fitWidth),
                ),
                SizedBox(
                  height: 50,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: TextField(
                          controller: Username,
                          decoration: InputDecoration(
                            prefixIcon: Icon(Icons.perm_identity),
                          ),
                        ),
                      ),
                    ),
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: TextField(
                          controller: mobile,
                          decoration: InputDecoration(
                            prefixIcon: Icon(Icons.mobile_screen_share),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Align(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        "User Information",
                        style: TextStyle(
                            fontSize: 15, fontWeight: FontWeight.bold),
                      )),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: TextField(
                          controller: Place,
                          decoration: InputDecoration(),
                        ),

                      ),
                    ),
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: TextField(
                          controller: age,
                          decoration: InputDecoration(
                            hintText: 'Age',
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: TextField(
                          controller: height,
                          decoration: InputDecoration(
                            hintText: 'Height(in cm)',
                          ),
                        ),
                      ),
                    ),
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: TextField(
                          controller: weight,
                          decoration: InputDecoration(
                            hintText: 'Weight(in kg)',
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }


  //  get & fill Shareprefrece data to textfield
  getDetails() async {
    Future user = SharedPrefrence().getUserMobile();
    Future name = SharedPrefrence().getUserName();
    Future place = SharedPrefrence().getUserPlace();

    user.then((data) async {
      var mobile_no = data;
      setState(() {
        if (mobile_no.isNotEmpty) {
          mobile.text = mobile_no;
        }
        else
          {
            mobile.text = "";
          }
      });
    });

    name.then((data) async {
      var user_name = data;
      setState(() {
        if (user_name.isNotEmpty) {
          Username.text = user_name;
        }
      });
    });

    place.then((data) async {
      var user_place = data;
      setState(() {
        if (user_place.isNotEmpty) {
          Place.text = user_place;
        }
      });
    });
  }



}
flutter dart flutter-layout
1个回答
0
投票

尝试使用文本字段方法,例如onChanged,onSubmitted,...也可以尝试使用焦点节点。

© www.soinside.com 2019 - 2024. All rights reserved.